
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 0.60 KB | hits: 11 | expires: Never
# me.rb
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.
```ruby
$ rails console
Loading development environment (Rails 3.1.0.rc4)
>> load 'me.rb'
=> nil
>> User.me
=> #<User _id: 4c14ba297826c943b2000002, encrypted_password: "16336dd440d4bbe843dc39....", .... >
```
I hope you find it useful!