class ActiveAdmin::ResourceController
All Resources Controller inherits from this controller. It implements actions and helpers for resources.
Public Class Methods
active_admin_config=(config)
click to toggle source
# 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)
click to toggle source
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.
Calls superclass method
# File lib/active_admin/resource_controller.rb, line 37 def self.inherited(base) super(base) base.override_resource_class_methods! end
Public Instance Methods
create(options={}, &block)
click to toggle source
Calls superclass method
# 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') } end end
Also aliased as: create!
edit(options={}, &block)
click to toggle source
Calls superclass method
# 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') } end end
Also aliased as: edit!
index(options={}, &block)
click to toggle source
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
Calls superclass method
# 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') } 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
Also aliased as: index!
new(options={}, &block)
click to toggle source
Calls superclass method
# 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') } end end
Also aliased as: new!
show(options={}, &block)
click to toggle source
Calls superclass method
# 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') } end end
Also aliased as: show!
update(options={}, &block)
click to toggle source
Calls superclass method
# 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') } end end
Also aliased as: update!
Protected Instance Methods
active_admin_template(template)
click to toggle source
Returns the full location to the Active Admin template path
# File lib/active_admin/resource_controller/actions.rb, line 70 def active_admin_template(template) "active_admin/resource/#{template}" end
csv_filename()
click to toggle source
Returns a filename for the csv file using the collection_name and current date such as 'my-articles-2011-06-24.csv'.
# 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
Private Instance Methods
renderer_for(action)
click to toggle source
Returns the renderer class to use for the given action.
# File lib/active_admin/resource_controller.rb, line 45 def renderer_for(action) active_admin_namespace.view_factory["#{action}_page"] end