Validator to ensure two fields are different?


#1

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


#2

Gary H. 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.


#3

----- Original Message -----
From: “Kevin O.” removed_email_address@domain.invalid
To: removed_email_address@domain.invalid
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.