s.nagesh
Joined: 23 Jul 2007 Posts: 115
|
Posted: Wed Jul 01, 2009 6:44 am Post subject: |
|
|
class YourModel < ActiveRecord::Base
validates_presence_of :value, :if => Proc.new {|p| p.radio_button_for_value}
attr_accessor :radio_button_for_value
end
The Proc here is bound to the object you're validating. So, the 'p' in this code is your object. In this case, if p.radio_button_for_value is nil or false, the validation will be skipped. If the rest of your validations pass, your object will return valid.
If you're looking for a specific value, use the follwing code.
class YourModel < ActiveRecord::Base
validates_presence_of :value, :if => Proc.new {|p| p.radio_button_for_value == value_to_skip_validation}
attr_accessor :radio_button_for_value
end |
|