validates_format_of :email, :with => %r{\.(edu|com)$}i, :message => "Must be a valid email address", :if => :some_method
Fred
validates_format_of :email, :with => %r{\.(edu|com)$}i, :message => "Must be a valid email address", :if => :some_method
Fred
Frederick Cheung wrote:
But if a certain cookie is set, I want to allow them to register with :message => "Must be a valid email address" --
validates_format_of :email, :with => %r{\.(edu|com)$}i, :message => "Must be a valid email address", :if => :some_method
Fred
Hmm, what kind of method would work in there? I tried
[snip]
But I get errors from both of them. How can I check for a cookie in the validation code?
Cookies are controller only. You will somehow have the let the model know that it's ok to skip the validation (eg set an attribute).
Fred
Cookies are controller only. You will somehow have the let the model know that it's ok to skip the validation (eg set an attribute).
Fred
Hmm, so there is no way to check for a cookie in the validation? That would make things so much easier...
Is there a way to check for the cookie in the controller and then pass through a parameter so that certain validation is skipped? Something like this in the controller, but make it only skip certain validation instead of all:
I've done similar things with something like
class User attr_accessor :extended_signup validates ... :if => :extended_signup end
at this point user.extended_signup = true user.save runs the validation user.extended_signup = false user.save doesn't
Fred