What validator can I use in a model to ensure that my :username field is different from my :password field? I''ve tried validates_exclusion_of :password, :in =>:username but I get a rails error "an object with the method include? is required must be supplied as the :in option of the configuration hash" Thanks! Gary
Kevin Olbrich
2006-Jan-11 03:38 UTC
[Rails] Re: validator to ensure two fields are different?
Gary Huntress wrote:> What validator can I use in a model to ensure that my :username field is > different from my :password field? > > I''ve tried > > validates_exclusion_of :password, :in =>:username > > but I get a rails error > "an object with the method include? is required must be supplied as the > :in > option of the configuration hash" > > Thanks! > > Garytry.. validates_exclusion_of :password, :in=>[username] this method requires an enumerable object for :in. A symbol (:username) is not enumerable, an array is. -- Posted via http://www.ruby-forum.com/.
Gary Huntress
2006-Jan-11 23:22 UTC
[Rails] Re: validator to ensure two fields are different?
----- Original Message ----- From: "Kevin Olbrich" <kevin.olbrich@duke.edu> To: <rails@lists.rubyonrails.org> Sent: Tuesday, January 10, 2006 10:38 PM Subject: [Rails] Re: validator to ensure two fields are different?> Gary Huntress wrote: >> What validator can I use in a model to ensure that my :username field is >> different from my :password field? >> >> I''ve tried >> >> validates_exclusion_of :password, :in =>:username >> >> but I get a rails error >> "an object with the method include? is required must be supplied as the >> :in >> option of the configuration hash" >> >> Thanks! >> >> Gary > > try.. > > validates_exclusion_of :password, :in=>[username] > > this method requires an enumerable object for :in. A symbol (:username) > is not enumerable, an array is.I tried validates_exclusion_of :password, :in=>[username] and that errors with "undefined local variable" I also tried validates_exclusion_of :password, :in=>[:username] and that does not error but does not catch the fields being equal. If you have any other suggestions that would be great! Gary H.