Hi how can I validate a field only if another field is set to a specific
value?
I tried to use
validates_length_of :fieldname, :maximum => 100, :if =>
:otherfieldname == ‘myvalue’
But doesn’t work
Thanks
Paolo
Hi how can I validate a field only if another field is set to a specific
value?
I tried to use
validates_length_of :fieldname, :maximum => 100, :if =>
:otherfieldname == ‘myvalue’
But doesn’t work
Thanks
Paolo
You can use blocks in your validations.
Try
validates_length_of :fieldname, :maximum => 100, :if => Proc.new{
|mymodel|
mymodel.otherfieldname == ‘myvaule’ }
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs