??Conditional validation skipping??

J

Joe Peck

Hey,

I have validation that I need to be able to bypass depending on a cookie
that the user might have.

My problem is for most users, they have to have a .edu or .com email
address. So I wrote that into the validation.

But if a certain cookie is set, I want to allow them to register with
any email address, and still run the other validations (uniqueness of
email, etc.)

Does anyone have any information on how to do this?

USER MODEL
validates_presence_of :first_name, :last_name, :email, :password
validates_uniqueness_of :email
validates_format_of :email,
:with => %r{\.(edu|com)$}i,
:message => "Must be a valid email address"
 
A

Alex LeDonne

Hey,

I have validation that I need to be able to bypass depending on a cookie
that the user might have.

My problem is for most users, they have to have a .edu or .com email
address. So I wrote that into the validation.

But if a certain cookie is set, I want to allow them to register with
any email address, and still run the other validations (uniqueness of
email, etc.)

Does anyone have any information on how to do this?

USER MODEL
validates_presence_of :first_name, :last_name, :email, :password
validates_uniqueness_of :email
validates_format_of :email,
:with => %r{\.(edu|com)$}i,
:message => "Must be a valid email address"


Maybe use a filter in the controller that does registration. Try the
rails list for more help:
http://groups.google.com/group/rubyonrails-talk
or
http://www.ruby-forum.com/forum/3
on ruby-forum.

-A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,271
Messages
2,571,361
Members
48,043
Latest member
BartEaster

Latest Threads

Top