Condition in validation

Is this right?

validates_uniqueness_of :email, :message => “Email taken”, :unless =>
:email == ‘[email protected]

On Aug 17, 6:22 pm, Pål Bergström [email protected]
wrote:

Is this right?

validates_uniqueness_of :email, :message => “Email taken”, :unless =>
:email == ‘[email protected]

no. :unless must be the name of a method that returns whether or not
to run the validation

Fred

Frederick C. wrote:

On Aug 17, 6:22�pm, P�l Bergstr�m [email protected]
wrote:

Is this right?

validates_uniqueness_of :email, :message => “Email taken”, :unless =>
:email == ‘[email protected]

no. :unless must be the name of a method that returns whether or not
to run the validation

Fred

How would I write a condition that doesn’t check the uniqueness of a
mail address if the address is ‘[email protected]

On Aug 17, 6:33 pm, Pål Bergström [email protected]
wrote:

Fred

How would I write a condition that doesn’t check the uniqueness of a
mail address if the address is ‘[email protected]

you write a method that returns true if the email is that magic value

Fred

validates_uniqueness_of :email, :message => “Email taken”, :unless =>
“email == ‘[email protected]’”

Frederick C. wrote:

On Aug 17, 6:33�pm, P�l Bergstr�m [email protected]
wrote:

Fred

How would I write a condition that doesn’t check the uniqueness of a
mail address if the address is ‘[email protected]

you write a method that returns true if the email is that magic value

Fred

I see. Now I understand. :slight_smile: Thanks.

Samer A. wrote:

validates_uniqueness_of :email, :message => “Email taken”, :unless =>
“email == ‘[email protected]’”

Nope.

Best,

Marnen Laibow-Koser
http://www.marnen.org
remove[email protected]

Unless I am severely mistaken, you can’t use :unless as a condition in
the validation anyway. It would need to be :if => some_condition,
where the some_condition method would return true/false.

On Aug 17, 1:22 pm, Pål Bergström [email protected]

Billee D. wrote:

Unless I am severely mistaken, you can’t use :unless as a condition in
the validation anyway. It would need to be :if => some_condition,
where the some_condition method would return true/false.

On Aug 17, 1:22�pm, P�l Bergstr�m [email protected]

It worked with :unless, as described in the API.

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