class ActiveAdmin::ResourceController
It implements actions and helpers for resources.
All Resources Controller inherits from this controller.
def active_admin_config=(config)
def active_admin_config=(config) @active_admin_config = config unless config.nil? defaults :resource_class => config.resource_class, :route_prefix => config.route_prefix, :instance_name => config.resource_name.singular end end
def active_admin_template(template)
def active_admin_template(template) "active_admin/resource/#{template}" end
def create(options={}, &block)
def create(options={}, &block) super(options) do |success, failure| block.call(success, failure) if block failure.html { render active_admin_template('new') } end end
def csv_filename
Returns a filename for the csv file using the collection_name
def csv_filename "#{resource_collection_name.to_s.gsub('_', '-')}-#{Time.now.strftime("%Y-%m-%d")}.csv" end
def determine_active_admin_layout
2. If we're rendering a custom action, we'll use the active_admin layout so
all the required layout code)
because these actions are subclasses of the Base page (which implementes
1. If we're rendering a standard Active Admin action, we want layout(false)
Determine which layout to use.
def determine_active_admin_layout ACTIVE_ADMIN_ACTIONS.include?(params[:action].to_sym) ? false : 'active_admin' end
def edit(options={}, &block)
def edit(options={}, &block) super do |format| block.call(format) if block format.html { render active_admin_template('edit') } end end
def index(options={}, &block)
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
def inherited(base)
add in the Base.resource_class class method. To override it, we
Inherited Resources uses the inherited(base) hook method to
def inherited(base) super(base) base.override_resource_class_methods! end
def new(options={}, &block)
def new(options={}, &block) super do |format| block.call(format) if block format.html { render active_admin_template('new') } end end
def renderer_for(action)
def renderer_for(action) active_admin_namespace.view_factory["#{action}_page"] end
def show(options={}, &block)
def show(options={}, &block) super do |format| block.call(format) if block format.html { render active_admin_template('show') } end end
def update(options={}, &block)
def update(options={}, &block) super do |success, failure| block.call(success, failure) if block failure.html { render active_admin_template('edit') } end end