![](/img/trans.png)
[英]Is before_action/filter in application_controller.rb a bad practice?
[英]Set filter before_action for ActiveAdmin controller
我想將before_action過濾器添加到 ActiveAdmin 控制器。
我可以做這樣的事情:
before_action :set_product, only: [:show, :edit, :update, :destroy]
private
def set_product
@product = Product.find_by_name(params[:name])
end
您可以從控制器內部訪問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
您可以將其存儲在配置中: config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
def do_something_awesome
end
config.before_action :do_something_awesome
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.