Class: ActiveAdmin::Resource
- Inherits:
 - 
      Object
      
        
- Object
 - ActiveAdmin::Resource
 
 
- Includes:
 - Authorization, ActionItems, Attributes, Base, Controllers, Includes, Menu, Naming, Ordering, PagePresenters, Pagination, Routes, ScopeTo, Scopes, Sidebars, MethodOrProcHelper
 
- Defined in:
 - lib/active_admin/resource.rb,
lib/active_admin/resource/menu.rb,
lib/active_admin/resource/naming.rb,
lib/active_admin/resource/routes.rb,
lib/active_admin/resource/scopes.rb,
lib/active_admin/resource/includes.rb,
lib/active_admin/resource/ordering.rb,
lib/active_admin/resource/scope_to.rb,
lib/active_admin/resource/sidebars.rb,
lib/active_admin/resource/attributes.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, Attributes, Base, Controllers, Includes, Menu, Naming, Ordering, PagePresenters, Pagination, Routes, ScopeTo, Scopes, Sidebars Classes: BelongsTo, Name
Constant Summary collapse
- RegisterEvent =
          
Event dispatched when a new resource is registered
 "active_admin.resource.register".freeze
Constants included from Authorization
Authorization::CREATE, Authorization::DESTROY, Authorization::EDIT, Authorization::NEW, Authorization::READ, Authorization::UPDATE
Instance Attribute Summary collapse
- #breadcrumb ⇒ Object
 - 
  
    
      #collection_actions  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
An array of collection actions defined for this resource.
 - #create_another ⇒ Object
 - 
  
    
      #csv_builder  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The csv builder for this resource.
 - 
  
    
      #decorator_class_name  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The string identifying a class to decorate our resource with for the view.
 - 
  
    
      #dsl  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Store a reference to the DSL so that we can dereference it during garbage collection.
 - 
  
    
      #member_actions  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
An array of member actions defined for this resource.
 - 
  
    
      #namespace  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The namespace this config belongs to.
 - #order_clause ⇒ Object
 - 
  
    
      #resource_class_name  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The name of the resource class.
 - #sort_order ⇒ Object
 
Attributes included from Pagination
#max_per_page, #paginate, #per_page
Attributes included from Menu
Instance Method Summary collapse
- #association_columns ⇒ Object
 - #belongs_to(target, options = {}) ⇒ Object
 - 
  
    
      #belongs_to?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Do we belong to another resource?.
 - #belongs_to_config ⇒ Object
 - #belongs_to_param ⇒ Object
 - #clear_collection_actions! ⇒ Object
 - 
  
    
      #clear_member_actions!  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Clears all the member actions this resource knows about.
 - #content_columns ⇒ Object
 - #decorator_class ⇒ Object
 - 
  
    
      #defined_actions  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Return only defined resource actions.
 - #find_resource(id) ⇒ Object
 - #resource_attributes ⇒ Object
 - 
  
    
      #resource_class  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
The class this resource wraps.
 - #resource_column_names ⇒ Object
 - #resource_columns ⇒ Object
 - #resource_name_extension ⇒ Object
 - #resource_quoted_column_name(column) ⇒ Object
 - #resource_table_name ⇒ Object
 
Methods included from Attributes
#counter_cache_col?, #default_attributes, #filtered_col?, #foreign_methods, #method_for_column, #primary_col?, #reject_col?, #sti_col?
Methods included from Ordering
Methods included from Routes
#route_batch_action_path, #route_builder, #route_collection_path, #route_edit_instance_path, #route_instance_path, #route_member_action_path, #route_prefix, #route_uncountable?
Methods included from Sidebars
#clear_sidebar_sections!, #sidebar_sections, #sidebar_sections?, #sidebar_sections_for
Methods included from ScopeTo
#scope_to, #scope_to?, #scope_to_association_method, #scope_to_config, #scope_to_method
Methods included from Includes
Methods included from Scopes
#default_scope, #get_scope_by_id, #scope, #scopes
Methods included from Pagination
Methods included from PagePresenters
#default_index_class, #get_page_presenter, #page_presenters, #set_page_presenter
Methods included from Naming
#param_key, #plural_resource_label, #resource_label, #resource_name
Methods included from Menu
#add_to_menu, #default_menu_options, #include_in_menu?, #menu_item_options, #menu_item_options=, #navigation_menu, #navigation_menu_name, #navigation_menu_name=
Methods included from Controllers
Methods included from ActionItems
#action_items, #action_items?, #action_items_for, #add_action_item, #clear_action_items!, #initialize, #remove_action_item
Methods included from Base
Methods included from MethodOrProcHelper
#call_method_or_exec_proc, #call_method_or_proc_on, #render_in_context, #render_or_call_method_or_proc_on
Instance Attribute Details
#breadcrumb ⇒ Object
      166 167 168  | 
    
      # File 'lib/active_admin/resource.rb', line 166 def instance_variable_defined?(:@breadcrumb) ? @breadcrumb : namespace. end  | 
  
#collection_actions ⇒ Object (readonly)
An array of collection actions defined for this resource
      43 44 45  | 
    
      # File 'lib/active_admin/resource.rb', line 43 def collection_actions @collection_actions end  | 
  
#create_another ⇒ Object
      174 175 176  | 
    
      # File 'lib/active_admin/resource.rb', line 174 def create_another instance_variable_defined?(:@create_another) ? @create_another : namespace.create_another end  | 
  
#csv_builder ⇒ Object
The csv builder for this resource
      162 163 164  | 
    
      # File 'lib/active_admin/resource.rb', line 162 def csv_builder @csv_builder || default_csv_builder end  | 
  
#decorator_class_name ⇒ Object
The string identifying a class to decorate our resource with for the view. nil to not decorate.
      68 69 70  | 
    
      # File 'lib/active_admin/resource.rb', line 68 def decorator_class_name @decorator_class_name end  | 
  
#dsl ⇒ Object
Store a reference to the DSL so that we can dereference it during garbage collection.
      64 65 66  | 
    
      # File 'lib/active_admin/resource.rb', line 64 def dsl @dsl end  | 
  
#member_actions ⇒ Object (readonly)
An array of member actions defined for this resource
      40 41 42  | 
    
      # File 'lib/active_admin/resource.rb', line 40 def member_actions @member_actions end  | 
  
#namespace ⇒ Object (readonly)
The namespace this config belongs to
      34 35 36  | 
    
      # File 'lib/active_admin/resource.rb', line 34 def namespace @namespace end  | 
  
#order_clause ⇒ Object
      170 171 172  | 
    
      # File 'lib/active_admin/resource.rb', line 170 def order_clause @order_clause || namespace.order_clause end  | 
  
#resource_class_name ⇒ Object (readonly)
The name of the resource class
      37 38 39  | 
    
      # File 'lib/active_admin/resource.rb', line 37 def resource_class_name @resource_class_name end  | 
  
#sort_order ⇒ Object
      47 48 49  | 
    
      # File 'lib/active_admin/resource.rb', line 47 def sort_order @sort_order ||= (resource_class.respond_to?(:primary_key) ? resource_class.primary_key.to_s : "id") + "_desc" end  | 
  
Instance Method Details
#association_columns ⇒ Object
      191 192 193  | 
    
      # File 'lib/active_admin/resource.rb', line 191 def association_columns @association_columns ||= resource_attributes.select { |key, value| key != value }.values end  | 
  
#belongs_to(target, options = {}) ⇒ Object
      139 140 141 142 143 144  | 
    
      # File 'lib/active_admin/resource.rb', line 139 def belongs_to(target, = {}) @belongs_to = Resource::BelongsTo.new(self, target, ) self. = false if @belongs_to.required? [:class_name] ||= @belongs_to.resource.resource_class_name if @belongs_to.resource controller.send :belongs_to, target, .dup end  | 
  
#belongs_to? ⇒ Boolean
Do we belong to another resource?
      157 158 159  | 
    
      # File 'lib/active_admin/resource.rb', line 157 def belongs_to? !!belongs_to_config end  | 
  
#belongs_to_config ⇒ Object
      146 147 148  | 
    
      # File 'lib/active_admin/resource.rb', line 146 def belongs_to_config @belongs_to end  | 
  
#belongs_to_param ⇒ Object
      150 151 152 153 154  | 
    
      # File 'lib/active_admin/resource.rb', line 150 def belongs_to_param if belongs_to? && belongs_to_config.required? belongs_to_config.to_param end end  | 
  
#clear_collection_actions! ⇒ Object
      130 131 132  | 
    
      # File 'lib/active_admin/resource.rb', line 130 def clear_collection_actions! @collection_actions = [] end  | 
  
#clear_member_actions! ⇒ Object
Clears all the member actions this resource knows about
      126 127 128  | 
    
      # File 'lib/active_admin/resource.rb', line 126 def clear_member_actions! @member_actions = [] end  | 
  
#content_columns ⇒ Object
      195 196 197  | 
    
      # File 'lib/active_admin/resource.rb', line 195 def content_columns @content_columns ||= resource_attributes.select { |key, value| key == value }.values end  | 
  
#decorator_class ⇒ Object
      105 106 107  | 
    
      # File 'lib/active_admin/resource.rb', line 105 def decorator_class decorator_class_name&.constantize end  | 
  
#defined_actions ⇒ Object
Return only defined resource actions
      135 136 137  | 
    
      # File 'lib/active_admin/resource.rb', line 135 def defined_actions controller.instance_methods.map(&:to_sym) & ResourceController::ACTIVE_ADMIN_ACTIONS end  | 
  
#find_resource(id) ⇒ Object
      178 179 180 181  | 
    
      # File 'lib/active_admin/resource.rb', line 178 def find_resource(id) resource = resource_class.public_send *method_for_find(id) (decorator_class && resource) ? decorator_class.new(resource) : resource end  | 
  
#resource_attributes ⇒ Object
      187 188 189  | 
    
      # File 'lib/active_admin/resource.rb', line 187 def resource_attributes @resource_attributes ||= default_attributes end  | 
  
#resource_class ⇒ Object
The class this resource wraps. If you register the Post model, Resource#resource_class will point to the Post class
      101 102 103  | 
    
      # File 'lib/active_admin/resource.rb', line 101 def resource_class resource_class_name.constantize end  | 
  
#resource_column_names ⇒ Object
      117 118 119  | 
    
      # File 'lib/active_admin/resource.rb', line 117 def resource_column_names resource_class.column_names end  | 
  
#resource_columns ⇒ Object
      183 184 185  | 
    
      # File 'lib/active_admin/resource.rb', line 183 def resource_columns resource_attributes.values end  | 
  
#resource_name_extension ⇒ Object
      109 110 111  | 
    
      # File 'lib/active_admin/resource.rb', line 109 def resource_name_extension @resource_name_extension ||= define_resource_name_extension(self) end  | 
  
#resource_quoted_column_name(column) ⇒ Object
      121 122 123  | 
    
      # File 'lib/active_admin/resource.rb', line 121 def resource_quoted_column_name(column) resource_class.connection.quote_column_name(column) end  | 
  
#resource_table_name ⇒ Object
      113 114 115  | 
    
      # File 'lib/active_admin/resource.rb', line 113 def resource_table_name resource_class.quoted_table_name end  |