Guest User

Untitled

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