Speed-dial for your ActiveRecords! Set up shortcuts for commonly-accessed records so you can get them easily.
Tired of typing User.find_by_email("[email protected]")
to get your user? Now you can get it directly with User.chris
- Include the library in your ActiveRecord class
- Set up your favorites with the
favorite
method.
- First argument is the column to search, your favorite will forward to the
klass.find_by_<arg1>
method - Second argument is the shortcut name, and the value to search against
class User < ActiveRecord::Base
include Favorites
favorite :email, {
chris: "[email protected]",
joe: "[email protected]"
}
end
- That's it! Now you can use your favorite in your code or console.
- In this example,
User.chris
will translate intoUser.find_by_email("[email protected]")
- In this example,
User.joe
will translate intoUser.find_by_email("[email protected]")