Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Current user contains the user that is logged in
- >> current_user = User.find(6)
- >> pp current_user
- #<User id: 6, created_at: "2007-12-13 15:30:28", updated_at: "2007-12-13 15:30:33", email: "admin2", password: "dd3ca720302ead1415c21356d3aa2b309a4eaf9b", password_salt: "jU4rX0m9pn", password_hash_type: "sha1">
- >> User.find(6).destroy
- #<User id: 6, created_at: "2007-12-13 15:30:28", updated_at: "2007-12-13 15:30:33", email: "admin2", password: "dd3ca720302ead1415c21356d3aa2b309a4eaf9b", password_salt: "jU4rX0m9pn", password_hash_type: "sha1">
- >> pp current_user.valid?
- true
- >> User.find(6)
- ActiveRecord::RecordNotFound Exception: Couldn't find User with ID=6
- # Answer
- # In the application controller, first thing, I do is run this code. It checks to see if the user they had in their session is still valid or not.
- begin
- unless User.exists?(current_user)
- raise
- end
- rescue
- self.current_user = AnonymousUser.new
- end
Add Comment
Please, Sign In to add comment