Active Model Naming
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.
- M
- P
- R
- S
- U
Returns string to use for params names. It differs for namespaced models regarding whether it’s inside isolated engine.
For isolated engine: ::param_key(Blog::Post) #=> post
For shared engine: ::param_key(Blog::Post) #=> blog_post
Returns the plural class name of a record or class. Examples:
ActiveModel::Naming.plural(post) # => "posts" ActiveModel::Naming.plural(Highrise::Person) # => "highrise_people"
Returns string to use while generating route names. It differs for namespaced models regarding whether it’s inside isolated engine.
For isolated engine: ::route_key(Blog::Post) #=> posts
For shared engine: ::route_key(Blog::Post) #=> blog_posts
The route key also considers if the noun is uncountable and, in such cases, automatically appends _index.
Returns the singular class name of a record or class. Examples:
ActiveModel::Naming.singular(post) # => "post" ActiveModel::Naming.singular(Highrise::Person) # => "highrise_person"
Returns string to use while generating route names. It differs for namespaced models regarding whether it’s inside isolated engine.
For isolated engine: ::route_key(Blog::Post) #=> post
For shared engine: ::route_key(Blog::Post) #=> blog_post
Identifies whether the class name of a record or class is uncountable. Examples:
ActiveModel::Naming.uncountable?(Sheep) # => true ActiveModel::Naming.uncountable?(Post) => false
Returns an ActiveModel::Name object for module. It can be used to retrieve all kinds of naming-related information.