Validator to ensure two fields are different?

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

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.

----- Original Message -----
From: “Kevin O.” [email protected]
To: [email protected]
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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs