Methods
H
N
Attributes
[R] cache_key
[R] collection
[R] element
[R] i18n_key
[R] param_key
[R] partial_path
[R] plural
[R] route_key
[R] singular
[R] singular_route_key
Class Public methods
new(klass, namespace = nil, name = nil)
# File activemodel/lib/active_model/naming.rb, line 15
def initialize(klass, namespace = nil, name = nil)
  name ||= klass.name

  raise ArgumentError, "Class name cannot be blank. You need to supply a name argument when anonymous class given" if name.blank?

  super(name)

  @unnamespaced = self.sub(/^#{namespace.name}::/, '') if namespace
  @klass        = klass
  @singular     = _singularize(self).freeze
  @plural       = ActiveSupport::Inflector.pluralize(@singular).freeze
  @element      = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze
  @human        = ActiveSupport::Inflector.humanize(@element).freeze
  @collection   = ActiveSupport::Inflector.tableize(self).freeze
  @partial_path = "#{@collection}/#{@element}".freeze
  @param_key    = (namespace ? _singularize(@unnamespaced) : @singular).freeze
  @i18n_key     = self.underscore.to_sym

  @route_key          = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural.dup)
  @singular_route_key = ActiveSupport::Inflector.singularize(@route_key).freeze
  @route_key << "_index" if @plural == @singular
  @route_key.freeze
end
Instance Public methods
human(options={})

Transform the model name into a more humane format, using I18n. By default, it will underscore then humanize the class name

BlogPost.model_name.human # => "Blog post"

Specify optionswith additional translating options.

# File activemodel/lib/active_model/naming.rb, line 45
def human(options={})
  return @human unless @klass.respond_to?(:lookup_ancestors) &&
                       @klass.respond_to?(:i18n_scope)

  defaults = @klass.lookup_ancestors.map do |klass|
    klass.model_name.i18n_key
  end

  defaults << options[:default] if options[:default]
  defaults << @human

  options = {:scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults}.merge(options.except(:default))
  I18n.translate(defaults.shift, options)
end