class ActiveAdmin::Resource
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.
Constants
- RegisterEvent
Event dispatched when a new resource is registered
Attributes
An array of collection actions defined for this resource
Set the configuration for the CSV
The string identifying a class to decorate our resource with for the view. nil to not decorate.
Store a reference to the DSL
so that we can dereference it during garbage collection.
An array of member actions defined for this resource
The namespace this config belongs to
The name of the resource class
The default sort order to use in the controller
Public Instance Methods
# File lib/active_admin/resource.rb, line 121 def belongs_to(target, options = {}) @belongs_to = Resource::BelongsTo.new(self, target, options) self.navigation_menu_name = target unless @belongs_to.optional? controller.send :belongs_to, target, options.dup end
Do we belong to another resource?
# File lib/active_admin/resource.rb, line 132 def belongs_to? !!belongs_to_config end
# File lib/active_admin/resource.rb, line 127 def belongs_to_config @belongs_to end
# File lib/active_admin/resource.rb, line 112 def clear_collection_actions! @collection_actions = [] end
Clears all the member actions this resource knows about
# File lib/active_admin/resource.rb, line 108 def clear_member_actions! @member_actions = [] end
The csv builder for this resource
# File lib/active_admin/resource.rb, line 137 def csv_builder @csv_builder || default_csv_builder end
# File lib/active_admin/resource.rb, line 91 def decorator_class ActiveSupport::Dependencies.constantize(decorator_class_name) if decorator_class_name end
Return only defined resource actions
# File lib/active_admin/resource.rb, line 117 def defined_actions controller.instance_methods.map(&:to_sym) & ResourceController::ACTIVE_ADMIN_ACTIONS end
# File lib/active_admin/resource.rb, line 141 def find_resource(id) resource = resource_class.where(resource_class.primary_key => id).first decorator_class ? decorator_class.new(resource) : resource end
@deprecated
# File lib/active_admin/resource.rb, line 147 def resource resource_class end
The class this resource wraps. If you register the Post model, Resource#resource_class
will point to the Post class
# File lib/active_admin/resource.rb, line 87 def resource_class ActiveSupport::Dependencies.constantize(resource_class_name) end
# File lib/active_admin/resource.rb, line 99 def resource_column_names resource_class.column_names end
# File lib/active_admin/resource.rb, line 103 def resource_quoted_column_name(column) resource_class.connection.quote_column_name(column) end
# File lib/active_admin/resource.rb, line 95 def resource_table_name resource_class.quoted_table_name end
# File lib/active_admin/resource.rb, line 42 def sort_order @sort_order ||= (resource_class.respond_to?(:primary_key) ? resource_class.primary_key.to_s : 'id') + '_desc' end
Private Instance Methods
# File lib/active_admin/resource.rb, line 155 def default_csv_builder @default_csv_builder ||= CSVBuilder.default_for_resource(resource_class) end