Marcel Buchholz wrote:> Hi there!
>
> I have a problem with validations: My user model allways validates the
> presence of login, password and password_confirmation -
> it also does this if I use update_attributes to update a single
> attribute.
>
> So for example updating "username" fails, because I of course do
NOT
> provide
> password, password_confirmation etc. when only updating one attribute.
>
> So: How can I make stuff like "username" updateable by
update_attributes
> and
> still make sure that login, password etc have to be validaten when I
> do not change a single attribute but the entire record?
Something like this should work:
validates_confirmation_of :password, :if => :need_to_confirm_pw
private
def need_to_confirm_pw
return true if new_record?
return self.class.find(id).password != self[''password'']
end
This assumes that whatever processing you do to the password field has
already been done on assignment.
--Al Evans
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---