Hi,
I need to selectively turn off validations for example, I want to
make sure that password and password_confirmation fields are equal when
user
first signs up or changes his password from his profile, but not in
other
cases e.g. updates his profile.
right now I am using a quick and dirty hack by using booleans
e.g.
if(@skip_password_validations != false) #–do validations --#
is there anything better than this. any help would be greatly
appreciated.
–
Ishaq
http://blogs.kahaf.com/ishaq
- Programming can be fun, so can be cryptography, however they should
not be
combined …
On 11 Feb 2008, at 14:15, Rick DeNatale wrote:
cases e.g. updates his profile.
validates_presence_of :password, :unless =>
:skip_password_validations?
validates_presence_of :password_confirmation, unless =>
:skip_password_validations?
validates_confirmation_of :password, unless =>
:skip_password_validations?
def skip_password_validations?
@skip_password_validations
end
or even
with_options :unless => skip_password_validations? do
validates_presence_of :password
validates_presence_of :password_confirmation
validates_confirmation_of :password
end
On 2/11/08, Muhammad I. [email protected] wrote:
is there anything better than this. any help would be greatly
appreciated.
Something like this:
validates_presence_of :password, :unless =>
:skip_password_validations?
validates_presence_of :password_confirmation, unless =>
:skip_password_validations?
validates_confirmation_of :password, unless =>
:skip_password_validations?
def skip_password_validations?
@skip_password_validations
end
–
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denhaven2.com/
Thanks a lot, that really helps cleaning the code a little
On Feb 11, 2008 7:55 PM, Frederick C. [email protected]
wrote:
make sure that password and password_confirmation fields are equal
appreciated.
def skip_password_validations?
–
Ishaq
http://blogs.kahaf.com/ishaq
- Programming can be fun, so can be cryptography, however they should
not be
combined …
What about the :if parameter that validations can take?
Like this:
validates_format_of :password,
:with => /^\w+$/,
:message => ‘Password must be alphanumeric</
b>’,
:on => :save
:if => @skip_password_validations
The parameter can even be a Proc!
Muhammad I. wrote:
e.g.
if(@skip_password_validations != false) #–do validations --#
is there anything better than this. any help would be greatly
appreciated.
What I’m doing looks like this:
validates_format_of :password, :with => /^\w+$/, :message => ‘Password must be alphanumeric’, :on => :save
validates_length_of :password, :minimum => 5, :message => ‘Password to short (Must be 5 characters long)’, :on =>
:create