Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 681
Mike Andrianov Avatar asked Feb 06 '14 14:02

Mike Andrianov


2 Answers

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
like image 114
seanlinsley Avatar answered Nov 06 '22 06:11

seanlinsley


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
like image 23
thisismydesign Avatar answered Nov 06 '22 05:11

thisismydesign