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/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/pagination.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
Constant Summary collapse
- RegisterEvent =
Event dispatched when a new resource is registered
'active_admin.resource.register'.freeze
Instance Attribute Summary collapse
-
#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 config belongs to.
-
#resource_class_name ⇒ Object
readonly
The name of the resource class.
-
#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.
Attributes included from Pagination
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.
- #include_in_menu? ⇒ Boolean
- #resource ⇒ Object deprecated Deprecated.
-
#resource_class ⇒ Object
The class this resource wraps.
- #resource_quoted_column_name(column) ⇒ Object
- #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.
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_safe_resource_name, #plural_underscored_resource_name, #resource_key, #resource_name, #safe_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 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
#collection_actions ⇒ Object (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 |
#csv_builder ⇒ Object
The csv builder for this resource
136 137 138 |
# File 'lib/active_admin/resource.rb', line 136 def csv_builder @csv_builder || default_csv_builder end |
#member_actions ⇒ Object (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 |
#namespace ⇒ Object (readonly)
The namespace this config belongs to
27 28 29 |
# File 'lib/active_admin/resource.rb', line 27 def namespace @namespace end |
#resource_class_name ⇒ Object (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 |
#scope_to ⇒ Object
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 |
#scope_to_association_method ⇒ Object
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 |
#sort_order ⇒ Object
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
#admin_notes? ⇒ Boolean
Are admin notes turned on for this resource
113 114 115 |
# File 'lib/active_admin/resource.rb', line 113 def admin_notes? admin_notes.nil? ? ActiveAdmin.admin_notes : admin_notes end |
#belongs_to(target, options = {}) ⇒ Object
117 118 119 120 |
# File 'lib/active_admin/resource.rb', line 117 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
127 128 129 |
# File 'lib/active_admin/resource.rb', line 127 def belongs_to? !belongs_to_config.nil? end |
#belongs_to_config ⇒ Object
122 123 124 |
# File 'lib/active_admin/resource.rb', line 122 def belongs_to_config @belongs_to end |
#clear_collection_actions! ⇒ Object
108 109 110 |
# File 'lib/active_admin/resource.rb', line 108 def clear_collection_actions! @collection_actions = [] end |
#clear_member_actions! ⇒ Object
Clears all the member actions this resource knows about
104 105 106 |
# File 'lib/active_admin/resource.rb', line 104 def clear_member_actions! @member_actions = [] end |
#include_in_menu? ⇒ Boolean
131 132 133 |
# File 'lib/active_admin/resource.rb', line 131 def super && !(belongs_to? && !belongs_to_config.optional?) end |
#resource ⇒ Object
141 142 143 |
# File 'lib/active_admin/resource.rb', line 141 def resource resource_class end |
#resource_class ⇒ Object
The class this resource wraps. If you register the Post model, Resource#resource_class will point to the Post class
72 73 74 |
# File 'lib/active_admin/resource.rb', line 72 def resource_class ActiveSupport::Dependencies.constantize(resource_class_name) end |
#resource_quoted_column_name(column) ⇒ Object
80 81 82 |
# File 'lib/active_admin/resource.rb', line 80 def resource_quoted_column_name(column) resource_class.connection.quote_column_name(column) end |
#resource_table_name ⇒ Object
76 77 78 |
# File 'lib/active_admin/resource.rb', line 76 def resource_table_name resource_class.quoted_table_name end |
#route_collection_path ⇒ Object
Returns a symbol for the route to use to get to the collection of this resource
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/active_admin/resource.rb', line 91 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_path ⇒ Object
Returns the named route for an instance of this resource
85 86 87 |
# File 'lib/active_admin/resource.rb', line 85 def route_instance_path [route_prefix, controller.resources_configuration[:self][:route_instance_name], 'path'].compact.join('_').to_sym end |