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.


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

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”


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

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”


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

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

#resource_nameObject


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

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