Class: ActiveAdmin::ResourceController
- Inherits:
-
InheritedResources::Base
- Object
- InheritedResources::Base
- ActiveAdmin::ResourceController
- Includes:
- Actions, Callbacks, ActionBuilder, Collection, Filters, Form, Menu, PageConfigurations, Scoping
- Defined in:
- lib/active_admin/resource_controller.rb,
lib/active_admin/resource_controller/form.rb,
lib/active_admin/resource_controller/menu.rb,
lib/active_admin/resource_controller/actions.rb,
lib/active_admin/resource_controller/filters.rb,
lib/active_admin/resource_controller/scoping.rb,
lib/active_admin/resource_controller/sidebars.rb,
lib/active_admin/resource_controller/callbacks.rb,
lib/active_admin/resource_controller/collection.rb,
lib/active_admin/resource_controller/action_builder.rb,
lib/active_admin/resource_controller/page_configurations.rb
Direct Known Subclasses
Defined Under Namespace
Modules: ActionBuilder, Callbacks, Collection, Filters, Form, Menu, PageConfigurations, Scoping, Sidebars
Constant Summary collapse
- ACTIVE_ADMIN_ACTIONS =
[:index, :show, :new, :create, :edit, :update, :destroy]
Class Attribute Summary collapse
-
.active_admin_config ⇒ Object
Reference to the Resource object which initialized this controller.
Instance Method Summary collapse
- #active_admin_application ⇒ Object protected
- #active_admin_config ⇒ Object protected
-
#active_admin_template(template) ⇒ Object
protected
Returns the full location to the Active Admin template path.
-
#authenticate_active_admin_user ⇒ Object
protected
Calls the authentication method as defined in ActiveAdmin.authentication_method.
- #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’.
- #current_active_admin_user ⇒ Object protected
- #current_active_admin_user? ⇒ Boolean protected
-
#determine_active_admin_layout ⇒ Object
protected
Determine which layout to use.
- #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!)
-
#only_render_implemented_actions ⇒ Object
protected
By default Rails will render un-implemented actions when the view exists.
-
#renderer_for(action) ⇒ Object
protected
Returns the renderer class to use for the given action.
- #show(options = {}, &block) ⇒ Object (also: #show!)
- #update(options = {}, &block) ⇒ Object (also: #update!)
Methods included from Scoping
#begin_of_association_chain, #method_for_association_chain
Methods included from PageConfigurations
Methods included from Menu
#current_menu, #set_current_tab
Methods included from Form
Methods included from Filters
Methods included from Collection::Pagination
#active_admin_collection, #paginate, #setup_pagination_for_csv
Methods included from Collection::Scoping
#active_admin_collection, #current_scope, #scope_collection
Methods included from Collection::Search
#active_admin_collection, #clean_search_params, #search
Methods included from Collection::Sorting
#active_admin_collection, #sort_order
Methods included from Collection::BaseCollection
#active_admin_collection, #collection, #scoped_collection
Class Attribute Details
.active_admin_config ⇒ Object
Reference to the Resource object which initialized this controller
41 42 43 |
# File 'lib/active_admin/resource_controller.rb', line 41 def active_admin_config @active_admin_config end |
Instance Method Details
#active_admin_application ⇒ Object (protected)
93 94 95 |
# File 'lib/active_admin/resource_controller.rb', line 93 def active_admin_application ActiveAdmin.application end |
#active_admin_config ⇒ Object (protected)
88 89 90 |
# File 'lib/active_admin/resource_controller.rb', line 88 def active_admin_config self.class.active_admin_config end |
#active_admin_template(template) ⇒ Object (protected)
Returns the full location to the Active Admin template path
69 70 71 |
# File 'lib/active_admin/resource_controller/actions.rb', line 69 def active_admin_template(template) "active_admin/resource/#{template}" end |
#authenticate_active_admin_user ⇒ Object (protected)
Calls the authentication method as defined in ActiveAdmin.authentication_method
74 75 76 |
# File 'lib/active_admin/resource_controller.rb', line 74 def authenticate_active_admin_user send(active_admin_application.authentication_method) if active_admin_application.authentication_method 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.html.arb') } 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’.
75 76 77 |
# File 'lib/active_admin/resource_controller/actions.rb', line 75 def csv_filename "#{resource_collection_name.to_s.gsub('_', '-')}-#{Time.now.strftime("%Y-%m-%d")}.csv" end |
#current_active_admin_user ⇒ Object (protected)
78 79 80 |
# File 'lib/active_admin/resource_controller.rb', line 78 def current_active_admin_user send(active_admin_application.current_user_method) if active_admin_application.current_user_method end |
#current_active_admin_user? ⇒ Boolean (protected)
83 84 85 |
# File 'lib/active_admin/resource_controller.rb', line 83 def current_active_admin_user? !current_active_admin_user.nil? end |
#determine_active_admin_layout ⇒ Object (protected)
Determine which layout to use.
1. If we're rendering a standard Active Admin action, we want layout(false)
because these actions are subclasses of the Base page (which implementes
all the required layout code)
2. If we're rendering a custom action, we'll use the active_admin layout so
that users can render any template inside Active Admin.
69 70 71 |
# File 'lib/active_admin/resource_controller.rb', line 69 def determine_active_admin_layout ACTIVE_ADMIN_ACTIONS.include?(params[:action].to_sym) ? false : 'active_admin' 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.html.arb') } 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.html.arb') } format.csv do headers['Content-Type'] = 'text/csv; charset=utf-8' headers['Content-Disposition'] = %{attachment; filename="#{csv_filename}"} render active_admin_template('index.csv.erb') 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.html.arb') } end end |
#only_render_implemented_actions ⇒ Object (protected)
By default Rails will render un-implemented actions when the view exists. Becuase Active Admin allows you to not render any of the actions by using the #actions method, we need to check if they are implemented.
58 59 60 |
# File 'lib/active_admin/resource_controller.rb', line 58 def only_render_implemented_actions raise AbstractController::ActionNotFound unless action_methods.include?(params[:action]) end |
#renderer_for(action) ⇒ Object (protected)
Returns the renderer class to use for the given action.
98 99 100 |
# File 'lib/active_admin/resource_controller.rb', line 98 def renderer_for(action) active_admin_application.view_factory["#{action}_page"] 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.html.arb') } 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.html.arb') } end end |