Class: ActiveAdmin::Resource
- 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/action_items.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, Menu, Naming, 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
-
#admin_notes ⇒ Object
Set to false to turn off admin notes.
-
#collection_actions ⇒ Object
readonly
An array of collection actions defined for this resource.
-
#csv_builder ⇒ Object
The csv builder for this resource.
-
#member_actions ⇒ Object
readonly
An array of member actions defined for this resource.
-
#namespace ⇒ Object
readonly
The namespace this resource belongs to.
-
#page_configs ⇒ Object
readonly
A hash of page configurations for the controller indexed by action name.
-
#resource ⇒ Object
readonly
The class this resource wraps.
-
#scope_to ⇒ Object
Scope this resource to an association in the controller.
-
#scope_to_association_method ⇒ Object
If we’re scoping resources, use this method on the parent to return the collection.
-
#sort_order ⇒ Object
The default sort order to use in the controller.
Instance Method Summary collapse
-
#admin_notes? ⇒ Boolean
Are admin notes turned on for this resource.
- #belongs_to(target, options = {}) ⇒ Object
-
#belongs_to? ⇒ Boolean
Do we belong to another resource.
- #belongs_to_config ⇒ Object
- #clear_collection_actions! ⇒ Object
-
#clear_member_actions! ⇒ Object
Clears all the member actions this resource knows about.
-
#controller ⇒ Object
Returns the controller for this resource.
-
#controller_name ⇒ Object
Returns a properly formatted controller name for this resource within its namespace.
- #resource_table_name ⇒ Object
-
#route_collection_path ⇒ Object
Returns a symbol for the route to use to get to the collection of this resource.
-
#route_instance_path ⇒ Object
Returns the named route for an instance of this resource.
-
#route_prefix ⇒ Object
Returns the routes prefix for this resource.
Methods included from Sidebars
#clear_sidebar_sections!, #initialize, #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_resource_name, #resource_name, #underscored_resource_name
Methods included from Menu
#include_in_menu?, #menu, #menu_item_display_if, #menu_item_name, #menu_item_priority, #menu_options, #parent_menu_item_name
Methods included from ActionItems
#action_items, #action_items_for, #add_action_item, #clear_action_items!, #initialize
Methods included from Base
Instance Attribute Details
#admin_notes ⇒ Object
Set to false to turn off admin notes
50 51 52 |
# File 'lib/active_admin/resource.rb', line 50 def admin_notes @admin_notes end |
#collection_actions ⇒ Object (readonly)
An array of collection actions defined for this resource
38 39 40 |
# File 'lib/active_admin/resource.rb', line 38 def collection_actions @collection_actions end |
#csv_builder ⇒ Object
The csv builder for this resource
134 135 136 |
# File 'lib/active_admin/resource.rb', line 134 def csv_builder @csv_builder || default_csv_builder end |
#member_actions ⇒ Object (readonly)
An array of member actions defined for this resource
35 36 37 |
# File 'lib/active_admin/resource.rb', line 35 def member_actions @member_actions end |
#namespace ⇒ Object (readonly)
The namespace this resource belongs to
25 26 27 |
# File 'lib/active_admin/resource.rb', line 25 def namespace @namespace end |
#page_configs ⇒ Object (readonly)
A hash of page configurations for the controller indexed by action name
32 33 34 |
# File 'lib/active_admin/resource.rb', line 32 def page_configs @page_configs end |
#resource ⇒ Object (readonly)
The class this resource wraps. If you register the Post model, Resource#resource will point to the Post class
29 30 31 |
# File 'lib/active_admin/resource.rb', line 29 def resource @resource end |
#scope_to ⇒ Object
Scope this resource to an association in the controller
44 45 46 |
# File 'lib/active_admin/resource.rb', line 44 def scope_to @scope_to end |
#scope_to_association_method ⇒ Object
If we’re scoping resources, use this method on the parent to return the collection
47 48 49 |
# File 'lib/active_admin/resource.rb', line 47 def scope_to_association_method @scope_to_association_method end |
#sort_order ⇒ Object
The default sort order to use in the controller
41 42 43 |
# File 'lib/active_admin/resource.rb', line 41 def sort_order @sort_order end |
Instance Method Details
#admin_notes? ⇒ Boolean
Are admin notes turned on for this resource
115 116 117 |
# File 'lib/active_admin/resource.rb', line 115 def admin_notes? admin_notes.nil? ? ActiveAdmin.admin_notes : admin_notes end |
#belongs_to(target, options = {}) ⇒ Object
119 120 121 122 |
# File 'lib/active_admin/resource.rb', line 119 def belongs_to(target, = {}) @belongs_to = Resource::BelongsTo.new(self, target, ) controller.belongs_to(target, .dup) end |
#belongs_to? ⇒ Boolean
Do we belong to another resource
129 130 131 |
# File 'lib/active_admin/resource.rb', line 129 def belongs_to? !belongs_to_config.nil? end |
#belongs_to_config ⇒ Object
124 125 126 |
# File 'lib/active_admin/resource.rb', line 124 def belongs_to_config @belongs_to end |
#clear_collection_actions! ⇒ Object
110 111 112 |
# File 'lib/active_admin/resource.rb', line 110 def clear_collection_actions! @collection_actions = [] end |
#clear_member_actions! ⇒ Object
Clears all the member actions this resource knows about
106 107 108 |
# File 'lib/active_admin/resource.rb', line 106 def clear_member_actions! @member_actions = [] end |
#controller ⇒ Object
Returns the controller for this resource
85 86 87 |
# File 'lib/active_admin/resource.rb', line 85 def controller @controller ||= controller_name.constantize end |
#controller_name ⇒ Object
Returns a properly formatted controller name for this resource within its namespace
80 81 82 |
# File 'lib/active_admin/resource.rb', line 80 def controller_name [namespace.module_name, camelized_resource_name.pluralize + "Controller"].compact.join('::') end |
#resource_table_name ⇒ Object
74 75 76 |
# File 'lib/active_admin/resource.rb', line 74 def resource_table_name resource.quoted_table_name end |
#route_collection_path ⇒ Object
Returns a symbol for the route to use to get to the collection of this resource
96 97 98 |
# File 'lib/active_admin/resource.rb', line 96 def route_collection_path [route_prefix, controller.resources_configuration[:self][:route_collection_name], 'path'].compact.join('_').to_sym end |
#route_instance_path ⇒ Object
Returns the named route for an instance of this resource
101 102 103 |
# File 'lib/active_admin/resource.rb', line 101 def route_instance_path [route_prefix, controller.resources_configuration[:self][:route_instance_name], 'path'].compact.join('_').to_sym end |
#route_prefix ⇒ Object
Returns the routes prefix for this resource
90 91 92 |
# File 'lib/active_admin/resource.rb', line 90 def route_prefix namespace.module_name.try(:underscore) end |