Creates a model_name method on your object.
To implement, just extend ActiveModel::Naming in your object:
class BookCover extend ActiveModel::Naming end BookCover.model_name # => "BookCover" BookCover.model_name.human # => "Book cover" BookCover.model_name.i18n_key # => "book_cover" BookModule::BookCover.model_name.i18n_key # => "book_module.book_cover"
Providing the functionality that ActiveModel::Naming provides in your object is required to pass the Active Model Lint test. So either extending the provided method below, or rolling your own is required..
Returns the plural class name of a record or class. Examples:
ActiveModel::Naming.plural(post) # => "posts" ActiveModel::Naming.plural(Highrise::Person) # => "highrise_people"
# File lib/active_model/naming.rb, line 72 72: def self.plural(record_or_class) 73: model_name_from_record_or_class(record_or_class).plural 74: end
Returns the singular class name of a record or class. Examples:
ActiveModel::Naming.singular(post) # => "post" ActiveModel::Naming.singular(Highrise::Person) # => "highrise_person"
# File lib/active_model/naming.rb, line 80 80: def self.singular(record_or_class) 81: model_name_from_record_or_class(record_or_class).singular 82: end
Identifies whether the class name of a record or class is uncountable. Examples:
ActiveModel::Naming.uncountable?(Sheep) # => true ActiveModel::Naming.uncountable?(Post) => false
# File lib/active_model/naming.rb, line 88 88: def self.uncountable?(record_or_class) 89: plural(record_or_class) == singular(record_or_class) 90: end
Returns an ActiveModel::Name object for module. It can be used to retrieve all kinds of naming-related information.
# File lib/active_model/naming.rb, line 64 64: def model_name 65: @_model_name ||= ActiveModel::Name.new(self) 66: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.