Set filter before_action for ActiveAdmin controller
12,633
Solution 1
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
Solution 2
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
Author by
Mike Andrianov
Updated on June 04, 2022Comments
-
Mike Andrianov almost 2 years
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
-
Oscar Barrett over 8 yearsFor newer versions of activeadmin,
before_filter
should be within the controller block. -
arogachev about 8 years@OscarBarrett No, it works for me for the latest version of Active Admin (at the moment of writing this).