Module: ActiveModel::Naming

### Home Classes Methods

### In Files

- lib/active_model/naming.rb

### Methods

- ::param_key
- ::plural
- ::route_key
- ::singular
- ::singular_route_key
- ::uncountable?
- #model_name

### Class/Module Index

Quicksearch

- ActiveModel
- ActiveModel::AttributeMethods
- ActiveModel::AttributeMethods::ClassMethods
- ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher
- ActiveModel::BlockValidator
- ActiveModel::Callbacks
- ActiveModel::Conversion
- ActiveModel::Dirty
- ActiveModel::EachValidator
- ActiveModel::Errors
- ActiveModel::Lint
- ActiveModel::Lint::Tests
- ActiveModel::MassAssignmentSecurity
- ActiveModel::MassAssignmentSecurity::BlackList
- ActiveModel::MassAssignmentSecurity::ClassMethods
- ActiveModel::MassAssignmentSecurity::Error
- ActiveModel::MassAssignmentSecurity::LoggerSanitizer
- ActiveModel::MassAssignmentSecurity::PermissionSet
- ActiveModel::MassAssignmentSecurity::Sanitizer
- ActiveModel::MassAssignmentSecurity::StrictSanitizer
- ActiveModel::MassAssignmentSecurity::WhiteList
- ActiveModel::MissingAttributeError
- ActiveModel::Name
- ActiveModel::Naming
- ActiveModel::Observer
- ActiveModel::ObserverArray
- ActiveModel::Observing
- ActiveModel::Observing::ClassMethods
- ActiveModel::SecurePassword
- ActiveModel::SecurePassword::ClassMethods
- ActiveModel::SecurePassword::InstanceMethodsOnActivation
- ActiveModel::Serialization
- ActiveModel::Serializers
- ActiveModel::Serializers::JSON
- ActiveModel::Serializers::Xml
- ActiveModel::StrictValidationFailed
- ActiveModel::Translation
- ActiveModel::Validations
- ActiveModel::Validations::AcceptanceValidator
- ActiveModel::Validations::Callbacks
- ActiveModel::Validations::Callbacks::ClassMethods
- ActiveModel::Validations::ClassMethods
- ActiveModel::Validations::ConfirmationValidator
- ActiveModel::Validations::ExclusionValidator
- ActiveModel::Validations::FormatValidator
- ActiveModel::Validations::HelperMethods
- ActiveModel::Validations::InclusionValidator
- ActiveModel::Validations::LengthValidator
- ActiveModel::Validations::NumericalityValidator
- ActiveModel::Validations::PresenceValidator
- ActiveModel::Validations::WithValidator
- ActiveModel::Validator

No matching classes.

# ActiveModel::Naming

## 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.

### Public Class Methods

param_key(record_or_class) click to toggle source

Returns string to use for params names. It differs for namespaced models regarding whether it's inside isolated engine.

For isolated engine: ActiveModel::Naming.param_key(Blog::Post) #=> post

For shared engine: ActiveModel::Naming.param_key(Blog::Post) #=> blog_post

    # File lib/active_model/naming.rb, line 157
    def self.param_key(record_or_class)
      model_name_from_record_or_class(record_or_class).param_key
    end

plural(record_or_class) click to toggle source

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 102
    def self.plural(record_or_class)
      model_name_from_record_or_class(record_or_class).plural
    end

route_key(record_or_class) click to toggle source

Returns string to use while generating route names. It differs for namespaced models regarding whether it's inside isolated engine.

For isolated engine: ActiveModel::Naming.route_key(Blog::Post) #=> posts

For shared engine: ActiveModel::Naming.route_key(Blog::Post) #=> blog_posts

The route key also considers if the noun is uncountable and, in such cases, automatically appends _index.

    # File lib/active_model/naming.rb, line 145
    def self.route_key(record_or_class)
      model_name_from_record_or_class(record_or_class).route_key
    end

singular(record_or_class) click to toggle source

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 110
    def self.singular(record_or_class)
      model_name_from_record_or_class(record_or_class).singular
    end

singular_route_key(record_or_class) click to toggle source

Returns string to use while generating route names. It differs for namespaced models regarding whether it's inside isolated engine.

For isolated engine: ActiveModel::Naming.route_key(Blog::Post) #=> post

For shared engine: ActiveModel::Naming.route_key(Blog::Post) #=> blog_post

    # File lib/active_model/naming.rb, line 130
    def self.singular_route_key(record_or_class)
      model_name_from_record_or_class(record_or_class).singular_route_key
    end

uncountable?(record_or_class) click to toggle source

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 118
    def self.uncountable?(record_or_class)
      plural(record_or_class) == singular(record_or_class)
    end

### Public Instance Methods

model_name() click to toggle source

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 89
    def model_name
      @_model_name ||= begin
        namespace = self.parents.detect do |n|
          n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
        end
        ActiveModel::Name.new(self, namespace)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.