class ActiveAdmin::ResourceDSL
This is the class where all the register blocks are evaluated.
Public Class Methods
new(config, resource_class)
click to toggle source
Calls superclass method
ActiveAdmin::DSL::new
# File lib/active_admin/resource_dsl.rb, line 4 def initialize(config, resource_class) @resource = resource_class super(config) end
Private Instance Methods
action(set, name, options = {}, &block)
click to toggle source
Member Actions give you the functionality of defining both the action and the route directly from your ActiveAdmin
registration block.
For example:
ActiveAdmin.register Post do member_action :comments do @post = Post.find(params[:id] @comments = @post.comments end end
Will create a new controller action comments and will hook it up to the named route (comments_admin_post_path) /admin/posts/:id/comments
You can treat everything within the block as a standard Rails controller action.
# File lib/active_admin/resource_dsl.rb, line 114 def action(set, name, options = {}, &block) set << ControllerAction.new(name, options) title = options.delete(:title) controller do callback = ActiveAdmin::Dependency.rails >= 4 ? :before_action : :before_filter send(callback, only: [name]) { @page_title = title } if title define_method(name, &block || Proc.new{}) end end
belongs_to(target, options = {})
click to toggle source
# File lib/active_admin/resource_dsl.rb, line 11 def belongs_to(target, options = {}) config.belongs_to(target, options) end
collection_action(name, options = {}, &block)
click to toggle source
# File lib/active_admin/resource_dsl.rb, line 129 def collection_action(name, options = {}, &block) action config.collection_actions, name, options, &block end
csv(options={}, &block)
click to toggle source
Configure the CSV format
For example:
csv do column :name column("Author") { |post| post.author.full_name } end csv col_sep: ";", force_quotes: true do column :name end
# File lib/active_admin/resource_dsl.rb, line 89 def csv(options={}, &block) options[:resource] = @resource config.csv_builder = CSVBuilder.new(options, &block) end
form(options = {}, &block)
click to toggle source
# File lib/active_admin/resource_dsl.rb, line 72 def form(options = {}, &block) config.set_page_presenter :form, ActiveAdmin::PagePresenter.new(options, &block) end
includes(*args)
click to toggle source
Store relations that should be included
# File lib/active_admin/resource_dsl.rb, line 26 def includes(*args) config.includes.push *args end
index(options = {}, &block)
click to toggle source
Configure the index page for the resource
# File lib/active_admin/resource_dsl.rb, line 62 def index(options = {}, &block) options[:as] ||= :table config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block) end
member_action(name, options = {}, &block)
click to toggle source
# File lib/active_admin/resource_dsl.rb, line 125 def member_action(name, options = {}, &block) action config.member_actions, name, options, &block end
permit_params(*args, &block)
click to toggle source
Rails 4 Strong Parameters Support
Either
permit_params :title, :author, :body, tags: []
Or
permit_params do defaults = [:title, :body] if current_user.admin? defaults + [:author] else defaults end end
Keys included in the ‘permitted_params` setting are automatically whitelisted.
# File lib/active_admin/resource_dsl.rb, line 50 def permit_params(*args, &block) param_key = config.param_key.to_sym controller do define_method :permitted_params do params.permit *active_admin_namespace.permitted_params, param_key => block ? instance_exec(&block) : args end end end
scope(*args, &block)
click to toggle source
Create a scope
# File lib/active_admin/resource_dsl.rb, line 21 def scope(*args, &block) config.scope(*args, &block) end
scope_to(*args, &block)
click to toggle source
Scope
collection to a relation
# File lib/active_admin/resource_dsl.rb, line 16 def scope_to(*args, &block) config.scope_to(*args, &block) end
show(options = {}, &block)
click to toggle source
Configure the show page for the resource
# File lib/active_admin/resource_dsl.rb, line 68 def show(options = {}, &block) config.set_page_presenter :show, ActiveAdmin::PagePresenter.new(options, &block) end