0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A simple twin field validator for Rails 3.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.0.0.beta4
 Project Readme

twin_validator¶ ↑

A simple twin field validator for Rails 3.

gem sources -a http://gemcutter.org/
gem install twin_validator

What is a twin field?¶ ↑

A twin field is a field that has a useless value unless a previous field has been set. This often manifiests itself as checkbox/text field or select/text field pair. Think in terms of a select box with one option for ‘Other’; the ‘Other’ option should show a text box, validated only when it it set as such.

You can validate the text field only when the previous field is set to your chosen value. Jump into your model and validate like so:

validates :field, :inclusion => { :in => [true, false }
validates :other_field, :twin => { :twins => [:field] }

For now, the only options you can use are:

:twins # An Enumerable of symbols to resolve as attributes of the model.
:check_against # A value that, if the twins are set to, this model should be validated as a result.

Copyright © 2010 Nathan Kleyn. See LICENSE for details.