Does anyone know of a way to update individual attributes with
validation? update_attribute disables the validation checks in the
record model, so I’m wondering if there’s a workaround for this.
In my application, I want to allow the user to update some or all the
attributes without having to enter :password and :password_confirmation,
both of which are subject to validation.
Does anyone know of a way to update individual attributes with
validation? update_attribute disables the validation checks in the
record model, so I’m wondering if there’s a workaround for this.
In my application, I want to allow the user to update some or all the
attributes without having to enter :password and :password_confirmation,
both of which are subject to validation.
Boram
You can disable validations with the :if option.
class User < AR::Base
attr_accessor :skip_password
validates_confirmation_of :password, :if => :password_required?
def password_required? @skip_password != true
end
end
Does anyone know of a way to update individual attributes with
validation? update_attribute disables the validation checks in the
record model, so I’m wondering if there’s a workaround for this.
In my application, I want to allow the user to update some or all the
attributes without having to enter :password and :password_confirmation,
both of which are subject to validation.
update_attributes (note the plural) call validation before updating, so
why not use that?
Because there are times when the user will not want to update their
password, and password and password_confirmation both have
validates_presence_of and validates_confirmation_of applied to them.
Rick, thanks very, very much for responding. The solution you gave works
for the case when I want to bypass password and password confirmation,
but does not for the case when I want to update the password. I think
the problem probably has to do with the fact that I’m using a hashed
password in my user model. I’ll post here if and when I find a work
around (of course, if anyone has already been through this issue, feel
free to enlighten my feeble mind).
Thanks!
Lee O’Mara wrote:
Boram Y. wrote:
Does anyone know of a way to update individual attributes with
validation? update_attribute disables the validation checks in the
record model, so I’m wondering if there’s a workaround for this.
In my application, I want to allow the user to update some or all the
attributes without having to enter :password and :password_confirmation,
both of which are subject to validation.
update_attributes (note the plural) call validation before updating, so
why not use that?
–
Lee
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.