Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. # me.rb
  3.  
  4. In almost every my project there is a model that refers to myself. It can be an instance of User, Staff, Admin, Dude, etc. I use it for logging in and testing staff. I use it many times in rails console as well. Because typing `User.where(:email => 'my@email.com').first` can by annoying so I've put together little snippet that work in Mongoid and AcitveRecord as well.
  5.  
  6. ```ruby
  7. $ rails console
  8. Loading development environment (Rails 3.1.0.rc4)
  9. >> load 'me.rb'
  10. => nil
  11. >> User.me
  12. => #<User _id: 4c14ba297826c943b2000002, encrypted_password: "16336dd440d4bbe843dc39....", .... >
  13. ```
  14.  
  15. I hope you find it useful!