class ActiveAdmin::ResourceDSL
This is the class where all the register blocks are evaluated.
def action(set, name, options = {}, &block)
action.
You can treat everything within the block as a standard Rails controller
the named route (comments_admin_post_path) /admin/posts/:id/comments
Will create a new controller action comments and will hook it up to
end
end
@comments = @post.comments
@post = Post.find(params[:id]
member_action :comments do
ActiveAdmin.register Post do
For example:
block.
action and the route directly from your ActiveAdmin registration
Member Actions give you the functionality of defining both the
def action(set, name, options = {}, &block) warn "Warning: method `#{name}` already defined" if controller.method_defined?(name) set << ControllerAction.new(name, options) title = options.delete(:title) controller do before_action(only: [name]) { @page_title = title } if title define_method(name, &block || Proc.new{}) end end
def belongs_to(target, options = {})
def belongs_to(target, options = {}) config.belongs_to(target, options) end
def collection_action(name, options = {}, &block)
def collection_action(name, options = {}, &block) action config.collection_actions, name, options, &block end
def csv(options = {}, &block)
end
column :name
csv col_sep: ";", force_quotes: true do
end
column("Author") { |post| post.author.full_name }
column :name
csv do
For example:
Configure the CSV format
def csv(options = {}, &block) options[:resource] = config config.csv_builder = CSVBuilder.new(options, &block) end
def decorate_with(decorator_class)
def decorate_with(decorator_class) # Force storage as a string. This will help us with reloading issues. # Assuming decorator_class.to_s will return the name of the class allows # us to handle a string or a class. config.decorator_class_name = "::#{ decorator_class }" end
def form(options = {}, &block)
def form(options = {}, &block) config.set_page_presenter :form, ActiveAdmin::PagePresenter.new(options, &block) end
def includes(*args)
def includes(*args) config.includes.push *args end
def index(options = {}, &block)
def index(options = {}, &block) options[:as] ||= :table config.set_page_presenter :index, ActiveAdmin::PagePresenter.new(options, &block) end
def member_action(name, options = {}, &block)
def member_action(name, options = {}, &block) action config.member_actions, name, options, &block end
def order_by(column, &block)
end
['COALESCE(NULLIF(last_name, ''), first_name), first_name', order_clause.order].join(' ')
order_by(:full_name) do |order_clause|
# by last_name but in the case that there is no last name, by first_name.
end
[order_clause.to_sql, 'NULLS LAST'].join(' ') if order_clause.order == 'desc'
order_by(:age) do |order_clause|
# nulls last
For example:
Redefine sort behaviour for column
def order_by(column, &block) config.ordering[column] = block end
def permit_params(*args, &block)
end
end
defaults
else
defaults + [:author]
if current_user.admin?
defaults = [:title, :body]
permit_params do
Or
permit_params :title, :author, :body, tags: []
Either
Keys included in the `permitted_params` setting are automatically whitelisted.
def permit_params(*args, &block) param_key = config.param_key.to_sym belongs_to_param = config.belongs_to_param create_another_param = :create_another if config.create_another controller do define_method :permitted_params do permitted_params = active_admin_namespace.permitted_params + Array.wrap(belongs_to_param) + Array.wrap(create_another_param) params.permit(*permitted_params, param_key => block ? instance_exec(&block) : args) end end end
def scope(*args, &block)
def scope(*args, &block) config.scope(*args, &block) end
def scope_to(*args, &block)
def scope_to(*args, &block) config.scope_to(*args, &block) end
def show(options = {}, &block)
def show(options = {}, &block) config.set_page_presenter :show, ActiveAdmin::PagePresenter.new(options, &block) end