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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With