Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C:/instant_rails/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3
- /lib/active_record/base.rb:1857:in `method_missing'
- #{RAILS_ROOT}/app/controllers/user_controller.rb:63:in `edit'
- USER_CONTROLLER>RB
- def edit
- @title = "Edit your User Information"
- @user = User.find(session[:user_id])
- if param_posted?(:user)
- attribute = params[:attribute]
- case attribute
- when "email"
- try_to_update @user, attribute
- when "password"
- if @user.correct_password?(params)
- try_to_update @user, attribute
- else
- @user.password_errors(params)
- #Handle password submission
- end
- end
- end
- #For security purposes, never fill in the password fields.
- @user.clear_password
- end
- USER.RB
- def correct_password?(params)
- current_password = params[:user] [:current_password]
- password == current_password
- end
- #Generate message for password errors.
- def password_errors(params)
- #Use User models valid? method to generate error message
- #for a password mismatch (if any)
- self.password = params[:user][:password]
- self.password_confirmation = params[:user][:password_confirmation]
- valid?
- #The current password is incorrect, so add an error message.
- errors.add(:current_password, "is incorrect")
- end
- end
Add Comment
Please, Sign In to add comment