Methods
H
N
Attributes
[R] singular
[R] plural
[R] element
[R] collection
[R] partial_path
[R] route_key
[R] param_key
[R] i18n_key
[R] cache_key
Class Public methods
new(klass, namespace = nil, name = nil)
# File activemodel/lib/active_model/naming.rb, line 10
def initialize(klass, namespace = nil, name = nil)
  name ||= klass.name
  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
  @route_key = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural).freeze
  @i18n_key = self.underscore.to_sym
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 options with additional translating options.

# File activemodel/lib/active_model/naming.rb, line 33
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