Forum: Ruby on Rails validator to ensure two fields are different?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
46fa933af973ed7e149737c9efecb429?d=identicon&s=25 Gary Huntress (Guest)
on 2006-01-11 04:09
(Received via mailing list)
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
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-11 04:38
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.
46fa933af973ed7e149737c9efecb429?d=identicon&s=25 Gary Huntress (Guest)
on 2006-01-12 00:23
(Received via mailing list)
----- 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?


>> :in
> 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.
This topic is locked and can not be replied to.