Module: AuxiliaryRails::ViewHelpers::HumanNameHelper

Defined in:
lib/auxiliary_rails/view_helpers/human_name_helper.rb

Instance Method Summary collapse

Instance Method Details

#human_name(model, attribute = nil, count: 1) ⇒ String

Human-readable name for a model or a model’s attribute

Parameters:

  • model (Class, Object)

    The model class or an instance of the model

  • attribute (Symbol, String, nil) (defaults to: nil)

    The attribute name (optional)

Returns:

  • (String)

    The human-readable name



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/auxiliary_rails/view_helpers/human_name_helper.rb', line 9

def human_name(model, attribute = nil, count: 1)
  if attribute.nil?
    model.model_name.human(count: count)
  else
    model = model.class unless model.is_a?(Class)
    if count > 1
      model.human_attribute_name(attribute).pluralize(count)
    else
      model.human_attribute_name(attribute)
    end
  end
end

#human_name_plural(model, attribute = nil, count: 2) ⇒ String

Human-readable name for a model or a model’s attribute plural form

Parameters:

  • model (Class, Object)

    The model class or an instance of the model

  • attribute (Symbol, String, nil) (defaults to: nil)

    The attribute name (optional)

Returns:

  • (String)

    The human-readable name in plural form



27
28
29
# File 'lib/auxiliary_rails/view_helpers/human_name_helper.rb', line 27

def human_name_plural(model, attribute = nil, count: 2)
  human_name(model, attribute, count: count)
end