Reputation: 3095
I want to add before_action filter to ActiveAdmin controller.
Could I do something like this:
before_action :set_product, only: [:show, :edit, :update, :destroy]
private
def set_product
@product = Product.find_by_name(params[:name])
end
Upvotes: 10
Views: 15247
Reputation: 25142
You can store it in the config: config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
def do_something_awesome
end
config.before_action :do_something_awesome
end
Upvotes: 3
Reputation: 3205
You can access the controller from within the controller do ... end
DSL:
ActiveAdmin.register User do
before_action :set_product, only: [:show, :edit, :update, :destroy]
controller do
def set_product
@product = Product.find_by_name(params[:name])
end
end
end
Upvotes: 24