我想将 before_action 过滤器添加到ActiveAdmin控制器。
我可以这样做:
before_action :set_product, only: [:show, :edit, :update, :destroy]
private
def set_product
@product = Product.find_by_name(params[:name])
end
答案 0 :(得分:14)
您可以从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
答案 1 :(得分:0)
您可以将其存储在配置中:config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
def do_something_awesome
end
config.before_action :do_something_awesome
end