简体   繁体   中英

Set filter before_action for ActiveAdmin controller

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM