Class: ActiveAdmin::Resource

Inherits:
Object
  • Object
show all
Includes:
ActionItems, Base, Controllers, Menu, Naming, PagePresenters, Scopes, Sidebars
Defined in:
lib/active_admin/resource.rb,
lib/active_admin/resource/menu.rb,
lib/active_admin/resource/naming.rb,
lib/active_admin/resource/scopes.rb,
lib/active_admin/resource/sidebars.rb,
lib/active_admin/resource/belongs_to.rb,
lib/active_admin/resource/controllers.rb,
lib/active_admin/resource/action_items.rb,
lib/active_admin/resource/page_presenters.rb

Overview

Resource is the primary data storage for resource configuration in Active Admin

When you register a resource (ActiveAdmin.register Post) you are actually creating a new Resource instance within the given Namespace.

The instance of the current resource is available in ResourceController and views by calling the #active_admin_config method.

Defined Under Namespace

Modules: ActionItems, Base, Controllers, Menu, Naming, PagePresenters, Scopes, Sidebars Classes: BelongsTo

Constant Summary collapse

RegisterEvent =

Event dispatched when a new resource is registered

'active_admin.resource.register'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Menu

#menu, #menu_item_display_if, #menu_item_name, #menu_item_priority, #menu_options, #parent_menu_item_name

Methods included from Sidebars

#clear_sidebar_sections!, #initialize, #sidebar_sections, #sidebar_sections?, #sidebar_sections_for

Methods included from Scopes

#default_scope, #get_scope_by_id, #scope, #scopes

Methods included from Naming

#camelized_resource_name, #plural_camelized_resource_name, #plural_resource_name, #plural_underscored_resource_name, #resource_key, #resource_name, #underscored_resource_name

Methods included from ActionItems

#action_items, #action_items?, #action_items_for, #add_action_item, #clear_action_items!, #initialize

Methods included from PagePresenters

#get_page_presenter, #page_presenters, #set_page_presenter

Methods included from Controllers

#controller, #controller_name, #route_prefix

Methods included from Base

#initialize

Instance Attribute Details

#collection_actionsObject (readonly)

An array of collection actions defined for this resource



35
36
37
# File 'lib/active_admin/resource.rb', line 35

def collection_actions
  @collection_actions
end

#csv_builderObject

The csv builder for this resource



130
131
132
# File 'lib/active_admin/resource.rb', line 130

def csv_builder
  @csv_builder || default_csv_builder
end

#member_actionsObject (readonly)

An array of member actions defined for this resource



32
33
34
# File 'lib/active_admin/resource.rb', line 32

def member_actions
  @member_actions
end

#namespaceObject (readonly)

The namespace this config belongs to



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

def namespace
  @namespace
end

#resource_class_nameObject (readonly)

The name of the resource class



29
30
31
# File 'lib/active_admin/resource.rb', line 29

def resource_class_name
  @resource_class_name
end

#scope_toObject

Scope this resource to an association in the controller



41
42
43
# File 'lib/active_admin/resource.rb', line 41

def scope_to
  @scope_to
end

#scope_to_association_methodObject

If we’re scoping resources, use this method on the parent to return the collection



44
45
46
# File 'lib/active_admin/resource.rb', line 44

def scope_to_association_method
  @scope_to_association_method
end

#sort_orderObject

The default sort order to use in the controller



38
39
40
# File 'lib/active_admin/resource.rb', line 38

def sort_order
  @sort_order
end

Instance Method Details

#admin_notes?Boolean

Are admin notes turned on for this resource

Returns:

  • (Boolean)


107
108
109
# File 'lib/active_admin/resource.rb', line 107

def admin_notes?
  admin_notes.nil? ? ActiveAdmin.admin_notes : admin_notes
end

#belongs_to(target, options = {}) ⇒ Object



111
112
113
114
# File 'lib/active_admin/resource.rb', line 111

def belongs_to(target, options = {})
  @belongs_to = Resource::BelongsTo.new(self, target, options)
  controller.belongs_to(target, options.dup)
end

#belongs_to?Boolean

Do we belong to another resource

Returns:

  • (Boolean)


121
122
123
# File 'lib/active_admin/resource.rb', line 121

def belongs_to?
  !belongs_to_config.nil?
end

#belongs_to_configObject



116
117
118
# File 'lib/active_admin/resource.rb', line 116

def belongs_to_config
  @belongs_to
end

#clear_collection_actions!Object



102
103
104
# File 'lib/active_admin/resource.rb', line 102

def clear_collection_actions!
  @collection_actions = []
end

#clear_member_actions!Object

Clears all the member actions this resource knows about



98
99
100
# File 'lib/active_admin/resource.rb', line 98

def clear_member_actions!
  @member_actions = []
end

#include_in_menu?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/active_admin/resource.rb', line 125

def include_in_menu?
  super && !(belongs_to? && !belongs_to_config.optional?)
end

#resourceObject

Deprecated.


135
136
137
# File 'lib/active_admin/resource.rb', line 135

def resource
  @resource_class
end

#resource_classObject

The class this resource wraps. If you register the Post model, Resource#resource_class will point to the Post class



70
71
72
# File 'lib/active_admin/resource.rb', line 70

def resource_class
  ActiveSupport::Dependencies.constantize(resource_class_name)
end

#resource_table_nameObject



74
75
76
# File 'lib/active_admin/resource.rb', line 74

def resource_table_name
  resource_class.quoted_table_name
end

#route_collection_pathObject

Returns a symbol for the route to use to get to the collection of this resource



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/active_admin/resource.rb', line 85

def route_collection_path
  route = super

  # Handle plural resources.
  if controller.resources_configuration[:self][:route_collection_name] ==
        controller.resources_configuration[:self][:route_instance_name]
    route = route.to_s.gsub('_path', '_index_path').to_sym
  end

  route
end

#route_instance_pathObject

Returns the named route for an instance of this resource



79
80
81
# File 'lib/active_admin/resource.rb', line 79

def route_instance_path
  [route_prefix, controller.resources_configuration[:self][:route_instance_name], 'path'].compact.join('_').to_sym
end