Class: ActiveAdmin::ResourceController

Inherits:
BaseController
  • Object
show all
Extended by:
ResourceClassMethods
Includes:
Actions, Callbacks, ActionBuilder, Collection, Filters, Scoping
Defined in:
lib/active_admin/resource_controller.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/resource_class_methods.rb

Overview

All Resources Controller inherits from this controller. It implements actions and helpers for resources.

Direct Known Subclasses

Dashboards::DashboardController

Defined Under Namespace

Modules: ActionBuilder, Callbacks, Collection, Filters, ResourceClassMethods, Scoping, Sidebars

Constant Summary collapse

ACTIVE_ADMIN_ACTIONS =
[:index, :show, :new, :create, :edit, :update, :destroy]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ResourceClassMethods

override_resource_class_methods!

Methods included from Scoping

#begin_of_association_chain, #method_for_association_chain

Methods included from Filters

#filters_config

Methods included from Collection::Pagination

#active_admin_collection, #paginate, #setup_pagination_for_csv

Methods included from Collection::Scoping

#active_admin_collection, #current_scope, #scope_current_collection

Methods included from ScopeChain

#scope_chain

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

Methods inherited from BaseController

#only_render_implemented_actions

Methods included from BaseController::Menu

#current_menu, #set_current_tab

Class Method Details

.active_admin_config=(config) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/active_admin/resource_controller.rb', line 30

def active_admin_config=(config)
  @active_admin_config = config

  defaults  :resource_class => config.resource_class,
            :route_prefix => config.route_prefix,
            :instance_name => config.underscored_resource_name
end

.inherited(base) ⇒ Object

Inherited Resources uses the inherited(base) hook method to add in the Base.resource_class class method. To override it, we need to install our resource_class method each time we’re inherited from.



41
42
43
44
# File 'lib/active_admin/resource_controller.rb', line 41

def 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



69
70
71
# File 'lib/active_admin/resource_controller/actions.rb', line 69

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(options={}, &block)
  super(options) do |success, failure|
    block.call(success, failure) if block
    failure.html { render active_admin_template('new.html.arb') }
  end
end

#csv_filenameObject (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

#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(options={}, &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(options={}, &block)
  super(options) 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(options={}, &block)
  super do |format|
    block.call(format) if block
    format.html { render active_admin_template('new.html.arb') }
  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(options={}, &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(options={}, &block)
  super do |success, failure|
    block.call(success, failure) if block
    failure.html { render active_admin_template('edit.html.arb') }
  end
end