Module: ActiveAdmin::Resource::Naming

Included in:
Page, ActiveAdmin::Resource
Defined in:
lib/active_admin/resource/naming.rb

Instance Method Summary collapse

Instance Method Details

#param_keyObject

Forms use the model's original `param_key`, so we can't use our custom `resource_name` when the model's been renamed in ActiveAdmin.


32
33
34
35
36
37
38
# File 'lib/active_admin/resource/naming.rb', line 32

def param_key
  if resource_class.respond_to? :model_name
    resource_class.model_name.param_key
  else
    resource_name.param_key
  end
end

#plural_resource_label(options = {}) ⇒ Object

Returns the plural version of this resource such as “Bank Accounts”


24
25
26
27
28
# File 'lib/active_admin/resource/naming.rb', line 24

def plural_resource_label(options = {})
  defaults = {count:   Helpers::I18n::PLURAL_MANY_COUNT,
              default: resource_label.pluralize.titleize}
  resource_name.translate defaults.merge options
end

#resource_labelObject

Returns the name to call this resource such as “Bank Account”


18
19
20
21
# File 'lib/active_admin/resource/naming.rb', line 18

def resource_label
  resource_name.translate count: 1,
    default: resource_name.to_s.gsub('::', ' ').titleize
end

#resource_nameObject


5
6
7
8
9
10
11
12
13
14
15
# File 'lib/active_admin/resource/naming.rb', line 5

def resource_name
  @resource_name ||= begin
    as = @options[:as].gsub /\s/, '' if @options[:as]

    if as || !resource_class.respond_to?(:model_name)
      Name.new resource_class, as
    else
      Name.new resource_class
    end
  end
end