Class: ActiveAdmin::ResourceController
- Inherits:
-
BaseController
- Object
- InheritedResources::Base
- BaseController
- ActiveAdmin::ResourceController
- Extended by:
- ResourceClassMethods
- Includes:
- ActionBuilder, DataAccess, Decorators, Scoping, Sidebars
- Defined in:
- lib/active_admin/resource_controller.rb,
lib/active_admin/resource_controller/actions.rb,
lib/active_admin/resource_controller/scoping.rb,
lib/active_admin/resource_controller/sidebars.rb,
lib/active_admin/resource_controller/decorators.rb,
lib/active_admin/resource_controller/data_access.rb,
lib/active_admin/resource_controller/action_builder.rb,
lib/active_admin/resource_controller/resource_class_methods.rb
Overview
All Resources Controller inherits from this controller. It implements actions and helpers for resources.
Defined Under Namespace
Modules: ActionBuilder, DataAccess, Decorators, ResourceClassMethods, Scoping, Sidebars
Constant Summary
Constants included from BaseController::Authorization
BaseController::Authorization::ACTIONS_DICTIONARY
Class Method Summary collapse
- .active_admin_config=(config) ⇒ Object
-
.inherited(base) ⇒ Object
Inherited Resources uses the ‘self.inherited(base)` hook to add in `self.resource_class`.
Instance Method Summary collapse
-
#active_admin_template(template) ⇒ Object
protected
Returns the full location to the Active Admin template path.
- #create(options = {}, &block) ⇒ Object (also: #create!)
-
#csv_filename ⇒ Object
protected
Returns a filename for the csv file using the collection_name and current date such as ‘my-articles-2011-06-24.csv’.
- #edit(options = {}, &block) ⇒ Object (also: #edit!)
-
#index(options = {}, &block) ⇒ Object
(also: #index!)
Override the InheritedResources actions to use the Active Admin templates.
- #new(options = {}, &block) ⇒ Object (also: #new!)
- #show(options = {}, &block) ⇒ Object (also: #show!)
- #update(options = {}, &block) ⇒ Object (also: #update!)
Methods included from ResourceClassMethods
override_resource_class_methods!
Methods included from Sidebars
#skip_sidebar!, #skip_sidebar?
Methods included from Scoping
#begin_of_association_chain, #method_for_association_chain
Methods included from DataAccess
#apply_authorization_scope, #apply_decorator, #apply_filtering, #apply_pagination, #apply_scoping, #apply_sorting, #build_new_resource, #build_resource, #clean_search_params, #collection, #collection_before_scope, #create_resource, #current_scope, #decorator?, #decorator_class, #destroy_resource, #find_collection, #find_resource, #max_csv_records, #max_per_page, #per_page, #resource, #save_resource, #scoped_collection, #update_resource
Methods included from ScopeChain
Methods included from Callbacks
Methods included from Decorators
#active_admin_collection, #resource
Methods inherited from BaseController
#only_render_implemented_actions
Methods included from BaseController::Authorization
#action_to_permission, #active_admin_authorization, #active_admin_authorization_adapter, #authorize!, #authorize_resource!, #authorized?, #dispatch_active_admin_access_denied, #rescue_active_admin_access_denied
Methods included from MethodOrProcHelper
#call_method_or_exec_proc, #call_method_or_proc_on, #render_in_context, #render_or_call_method_or_proc_on
Methods included from BaseController::Menu
#current_menu, #set_current_tab
Class Method Details
.active_admin_config=(config) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/active_admin/resource_controller.rb', line 26 def self.active_admin_config=(config) if @active_admin_config = config defaults :resource_class => config.resource_class, :route_prefix => config.route_prefix, :instance_name => config.resource_name.singular end end |
.inherited(base) ⇒ Object
Inherited Resources uses the ‘self.inherited(base)` hook to add in `self.resource_class`. To override it, we need to install our resource_class method each time we’re inherited from.
37 38 39 40 |
# File 'lib/active_admin/resource_controller.rb', line 37 def self.inherited(base) super(base) base.override_resource_class_methods! end |
Instance Method Details
#active_admin_template(template) ⇒ Object (protected)
Returns the full location to the Active Admin template path
70 71 72 |
# File 'lib/active_admin/resource_controller/actions.rb', line 70 def active_admin_template(template) "active_admin/resource/#{template}" end |
#create(options = {}, &block) ⇒ Object Also known as: create!
47 48 49 50 51 52 |
# File 'lib/active_admin/resource_controller/actions.rb', line 47 def create(={}, &block) super() do |success, failure| block.call(success, failure) if block failure.html { render active_admin_template('new') } end end |
#csv_filename ⇒ Object (protected)
Returns a filename for the csv file using the collection_name and current date such as ‘my-articles-2011-06-24.csv’.
76 77 78 |
# File 'lib/active_admin/resource_controller/actions.rb', line 76 def csv_filename "#{resource_collection_name.to_s.gsub('_', '-')}-#{Time.now.strftime("%Y-%m-%d")}.csv" end |
#edit(options = {}, &block) ⇒ Object Also known as: edit!
39 40 41 42 43 44 |
# File 'lib/active_admin/resource_controller/actions.rb', line 39 def edit(={}, &block) super do |format| block.call(format) if block format.html { render active_admin_template('edit') } end end |
#index(options = {}, &block) ⇒ Object Also known as: index!
Override the InheritedResources actions to use the Active Admin templates.
We ensure that the functionality provided by Inherited Resources is still available within any ResourceController
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/active_admin/resource_controller/actions.rb', line 10 def index(={}, &block) super() do |format| block.call(format) if block format.html { render active_admin_template('index') } format.csv do headers['Content-Type'] = 'text/csv; charset=utf-8' headers['Content-Disposition'] = %{attachment; filename="#{csv_filename}"} render active_admin_template('index') end end end |
#new(options = {}, &block) ⇒ Object Also known as: new!
31 32 33 34 35 36 |
# File 'lib/active_admin/resource_controller/actions.rb', line 31 def new(={}, &block) super do |format| block.call(format) if block format.html { render active_admin_template('new') } end end |
#show(options = {}, &block) ⇒ Object Also known as: show!
23 24 25 26 27 28 |
# File 'lib/active_admin/resource_controller/actions.rb', line 23 def show(={}, &block) super do |format| block.call(format) if block format.html { render active_admin_template('show') } end end |
#update(options = {}, &block) ⇒ Object Also known as: update!
55 56 57 58 59 60 |
# File 'lib/active_admin/resource_controller/actions.rb', line 55 def update(={}, &block) super do |success, failure| block.call(success, failure) if block failure.html { render active_admin_template('edit') } end end |