| Module | ActsAsStaticRecord::SingletonMethods |
| In: |
lib/acts_as_static_record.rb
|
Similar to acts_as_enumeration model returns the record where the acts_as_static_record :key option matches lookup If no key is specified, the primary_id column is used
class User < ActiveRecord::Base
acts_as_static_record :key => :user_name
end
Then later we can reference the objects by the user_name
User[:blythe] User['snowgiraffe']
The key used will be the underscore version of the name. Punctuation marks are removed. The following are equivalent:
User[:blythe_snowgiraffeawesome] User['blythe-SNOWGIRaffe AWESome'] user = User.first User[user.user_name] == user