Guest User

Untitled

a guest
Apr 11th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. C:/instant_rails/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3
  2. /lib/active_record/base.rb:1857:in `method_missing'
  3. #{RAILS_ROOT}/app/controllers/user_controller.rb:63:in `edit'
  4.  
  5.  
  6. USER_CONTROLLER>RB
  7.  
  8. def edit
  9. @title = "Edit your User Information"
  10. @user = User.find(session[:user_id])
  11. if param_posted?(:user)
  12. attribute = params[:attribute]
  13. case attribute
  14. when "email"
  15. try_to_update @user, attribute
  16. when "password"
  17. if @user.correct_password?(params)
  18. try_to_update @user, attribute
  19. else
  20. @user.password_errors(params)
  21. #Handle password submission
  22. end
  23. end
  24. end
  25. #For security purposes, never fill in the password fields.
  26. @user.clear_password
  27. end
  28.  
  29.  
  30. USER.RB
  31.  
  32. def correct_password?(params)
  33. current_password = params[:user] [:current_password]
  34. password == current_password
  35. end
  36.  
  37. #Generate message for password errors.
  38. def password_errors(params)
  39. #Use User models valid? method to generate error message
  40. #for a password mismatch (if any)
  41. self.password = params[:user][:password]
  42. self.password_confirmation = params[:user][:password_confirmation]
  43. valid?
  44. #The current password is incorrect, so add an error message.
  45. errors.add(:current_password, "is incorrect")
  46. end
  47. end
Add Comment
Please, Sign In to add comment