Rails validation "failing when succeeding"

Posted by Fredrik on Stack Overflow See other posts from Stack Overflow or by Fredrik
Published on 2010-04-01T10:01:15Z Indexed on 2010/04/01 10:03 UTC
Read the original article Hit count: 507

I have this in my user.rb: attr_accessor :old_password def validate unless password.nil? errors.add_to_base("Old password entered incorrect") unless self.valid_password? old_password end end

I have old_password as a a virtual attribute that has to be validated as matching with the current before updating to a new password. My problem is that upon correct entering ( password == password confirmation and self.valid_password? old_password ) an error will yield and pass me back to the form. The strange part is that the data will actually be updated in the database, and it will not on wrong input; although it will yield the very same error ("Old password entered incorrect"). What on earth am I doing wrong?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails