Class: ActiveAdmin::Resource
- Inherits:
-
Object
- Object
- ActiveAdmin::Resource
- Includes:
- ActionItems, Base, Controllers, Menu, Naming, PagePresenters, Pagination, Scopes, Sidebars
- Defined in:
- lib/active_admin/resource.rb,
lib/active_admin/resource/menu.rb,
lib/active_admin/resource/scopes.rb,
lib/active_admin/resource/naming.rb,
lib/active_admin/resource/sidebars.rb,
lib/active_admin/resource/pagination.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, Pagination, Scopes, Sidebars Classes: BelongsTo, Name
Constant Summary
- RegisterEvent =
Event dispatched when a new resource is registered
'active_admin.resource.register'.freeze
Instance Attribute Summary (collapse)
-
- (Object) breadcrumb
Set breadcrumb builder.
-
- (Object) collection_actions
readonly
An array of collection actions defined for this resource.
-
- (Object) csv_builder
The csv builder for this resource.
-
- (Object) decorator_class_name
The string identifying a class to decorate our resource with for the view.
-
- (Object) dsl
Store a reference to the DSL so that we can dereference it during garbage collection.
-
- (Object) member_actions
readonly
An array of member actions defined for this resource.
-
- (Object) namespace
readonly
The namespace this config belongs to.
-
- (Object) resource_class_name
readonly
The name of the resource class.
-
- (Object) scope_to
Scope this resource to an association in the controller.
-
- (Object) scope_to_association_method
If we're scoping resources, use this method on the parent to return the collection.
-
- (Object) sort_order
The default sort order to use in the controller.
Attributes included from Pagination
Instance Method Summary (collapse)
-
- (Boolean) admin_notes?
Are admin notes turned on for this resource.
- - (Object) belongs_to(target, options = {})
-
- (Boolean) belongs_to?
Do we belong to another resource.
- - (Object) belongs_to_config
- - (Object) clear_collection_actions!
-
- (Object) clear_member_actions!
Clears all the member actions this resource knows about.
- - (Object) decorator_class
-
- (Object) defined_actions
Return only defined resource actions.
- - (Boolean) include_in_menu?
- - (Object) resource deprecated Deprecated.
-
- (Object) resource_class
The class this resource wraps.
- - (Object) resource_column_names
- - (Object) resource_quoted_column_name(column)
- - (Object) resource_table_name
-
- (Object) route_collection_path
Returns a symbol for the route to use to get to the collection of this resource.
-
- (Object) route_instance_path
Returns the named route for an instance of this resource.
Methods included from Menu
#default_menu_options, #menu, #menu_item, #parent_menu_item_name
Methods included from Sidebars
#clear_sidebar_sections!, #sidebar_sections, #sidebar_sections?, #sidebar_sections_for
Methods included from Scopes
#default_scope, #get_scope_by_id, #scope, #scopes
Methods included from Naming
#plural_resource_label, #resource_label, #resource_name
Methods included from ActionItems
#action_items, #action_items?, #action_items_for, #add_action_item, #clear_action_items!, #initialize
Methods included from Pagination
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
Instance Attribute Details
- (Object) breadcrumb
Set breadcrumb builder
51 52 53 |
# File 'lib/active_admin/resource.rb', line 51 def @breadcrumb end |
- (Object) collection_actions (readonly)
An array of collection actions defined for this resource
36 37 38 |
# File 'lib/active_admin/resource.rb', line 36 def collection_actions @collection_actions end |
- (Object) csv_builder
The csv builder for this resource
159 160 161 |
# File 'lib/active_admin/resource.rb', line 159 def csv_builder @csv_builder || default_csv_builder end |
- (Object) decorator_class_name
The string identifying a class to decorate our resource with for the view. nil to not decorate.
58 59 60 |
# File 'lib/active_admin/resource.rb', line 58 def decorator_class_name @decorator_class_name end |
- (Object) dsl
Store a reference to the DSL so that we can dereference it during garbage collection.
54 55 56 |
# File 'lib/active_admin/resource.rb', line 54 def dsl @dsl end |
- (Object) member_actions (readonly)
An array of member actions defined for this resource
33 34 35 |
# File 'lib/active_admin/resource.rb', line 33 def member_actions @member_actions end |
- (Object) namespace (readonly)
The namespace this config belongs to
27 28 29 |
# File 'lib/active_admin/resource.rb', line 27 def namespace @namespace end |
- (Object) resource_class_name (readonly)
The name of the resource class
30 31 32 |
# File 'lib/active_admin/resource.rb', line 30 def resource_class_name @resource_class_name end |
- (Object) scope_to
Scope this resource to an association in the controller
42 43 44 |
# File 'lib/active_admin/resource.rb', line 42 def scope_to @scope_to end |
- (Object) scope_to_association_method
If we're scoping resources, use this method on the parent to return the collection
45 46 47 |
# File 'lib/active_admin/resource.rb', line 45 def scope_to_association_method @scope_to_association_method end |
- (Object) sort_order
The default sort order to use in the controller
39 40 41 |
# File 'lib/active_admin/resource.rb', line 39 def sort_order @sort_order end |
Instance Method Details
- (Boolean) admin_notes?
Are admin notes turned on for this resource
136 137 138 |
# File 'lib/active_admin/resource.rb', line 136 def admin_notes? admin_notes.nil? ? ActiveAdmin.admin_notes : admin_notes end |
- (Object) belongs_to(target, options = {})
140 141 142 143 |
# File 'lib/active_admin/resource.rb', line 140 def belongs_to(target, = {}) @belongs_to = Resource::BelongsTo.new(self, target, ) controller.belongs_to(target, .dup) end |
- (Boolean) belongs_to?
Do we belong to another resource
150 151 152 |
# File 'lib/active_admin/resource.rb', line 150 def belongs_to? !belongs_to_config.nil? end |
- (Object) belongs_to_config
145 146 147 |
# File 'lib/active_admin/resource.rb', line 145 def belongs_to_config @belongs_to end |
- (Object) clear_collection_actions!
126 127 128 |
# File 'lib/active_admin/resource.rb', line 126 def clear_collection_actions! @collection_actions = [] end |
- (Object) clear_member_actions!
Clears all the member actions this resource knows about
122 123 124 |
# File 'lib/active_admin/resource.rb', line 122 def clear_member_actions! @member_actions = [] end |
- (Object) decorator_class
86 87 88 |
# File 'lib/active_admin/resource.rb', line 86 def decorator_class ActiveSupport::Dependencies.constantize(decorator_class_name) if decorator_class_name end |
- (Object) defined_actions
Return only defined resource actions
131 132 133 |
# File 'lib/active_admin/resource.rb', line 131 def defined_actions controller.instance_methods.map { |m| m.to_sym } & ResourceController::ACTIVE_ADMIN_ACTIONS end |
- (Boolean) include_in_menu?
154 155 156 |
# File 'lib/active_admin/resource.rb', line 154 def super && !(belongs_to? && !belongs_to_config.optional?) end |
- (Object) resource
164 165 166 |
# File 'lib/active_admin/resource.rb', line 164 def resource resource_class end |
- (Object) resource_class
The class this resource wraps. If you register the Post model, Resource#resource_class will point to the Post class
82 83 84 |
# File 'lib/active_admin/resource.rb', line 82 def resource_class ActiveSupport::Dependencies.constantize(resource_class_name) end |
- (Object) resource_column_names
94 95 96 |
# File 'lib/active_admin/resource.rb', line 94 def resource_column_names resource_class.column_names end |
- (Object) resource_quoted_column_name(column)
98 99 100 |
# File 'lib/active_admin/resource.rb', line 98 def resource_quoted_column_name(column) resource_class.connection.quote_column_name(column) end |
- (Object) resource_table_name
90 91 92 |
# File 'lib/active_admin/resource.rb', line 90 def resource_table_name resource_class.quoted_table_name end |
- (Object) route_collection_path
Returns a symbol for the route to use to get to the collection of this resource
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/active_admin/resource.rb', line 109 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 |
- (Object) route_instance_path
Returns the named route for an instance of this resource
103 104 105 |
# File 'lib/active_admin/resource.rb', line 103 def route_instance_path [route_prefix, controller.resources_configuration[:self][:route_instance_name], 'path'].compact.join('_').to_sym end |