Module: InheritedResourcesViews::I18nHelper

Defined in:
lib/inherited_resources_views/i18n_helper.rb

Instance Method Summary collapse

Instance Method Details

#action_title(action, pluralize = false) ⇒ Object

Transform the action name into a more human format for page headings, using I18n.

action_title(:index) # => "Listing projects"

This helper is useful when creating page headings:

<h1><%= action_title(:index) %></h1>

renders:

<h1>Listing projects</h1>


46
47
48
49
50
# File 'lib/inherited_resources_views/i18n_helper.rb', line 46

def action_title(action, pluralize=false)
  translate_action(:titles, action, pluralize) do |model|
    "#{action.to_s.humanize} #{model}"
  end
end

#human_action(action, pluralize = false) ⇒ Object

Transform the action name into a more human format, using I18n.

human_action(:show) # => "Show"

This helper is useful when creating links:

<%= link_to human_action(:show), resource_url(blog) %>

renders:

<a href="/blogs/1">Show</a>


28
29
30
31
32
# File 'lib/inherited_resources_views/i18n_helper.rb', line 28

def human_action(action, pluralize=false)
  translate_action(:actions, action, pluralize) do |model|
    "#{action.to_s.humanize}"
  end
end

#human_resource(pluralize = false) ⇒ Object

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

human_resource # => "Project manager"


9
10
11
12
13
14
# File 'lib/inherited_resources_views/i18n_helper.rb', line 9

def human_resource(pluralize=false)
  human = I18n.t(resource_instance_name,
               :scope => [:activerecord, :models],
               :default => resource_instance_name.to_s.humanize)
  pluralize ? human.pluralize : human
end