Forum: Ruby on Rails Form Change Old Password

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jamal S. (Guest)
on 2007-05-31 14:12
Hello there,

I want my users to be able to change their password.

I wrote the code below but I need help to add error if the old password
he posted did not match the current password he have.

In the controller I have:
def my_profile_password
  return true unless request.post?
  @user = current_user
  if @user.check_password(params[:old_password])
    @user.update_attributes(params[:user])
    if @user.update
    end
  end
end

and in my model:
def check_password(password)
  if self.password == User.encrypt(password)
    true
  end
end

PS: I know I should use @user.errors.add("", "Old password is wrong"),
but where should I place it in my code?

I tried within check_password but this is not working :(

I appreciate any help :D
Jamal S. (Guest)
on 2007-05-31 14:23
Rails server is weird, things are not working, when I do changes and put
everything back like it was, it then starts working again??

This is not the first time its happening!
This topic is locked and can not be replied to.