Guest User

Untitled

a guest
Mar 10th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. # Current user contains the user that is logged in
  2. >> current_user = User.find(6)
  3. >> pp current_user
  4. #<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">
  5. >> User.find(6).destroy
  6. #<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">
  7. >> pp current_user.valid?
  8. true
  9. >> User.find(6)
  10. ActiveRecord::RecordNotFound Exception: Couldn't find User with ID=6
  11.  
  12.  
  13. # Answer
  14. # 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.
  15. begin
  16. unless User.exists?(current_user)
  17. raise
  18. end
  19. rescue
  20. self.current_user = AnonymousUser.new
  21. end
Add Comment
Please, Sign In to add comment