Skip before filter with Active Admin

前端 未结 4 929
逝去的感伤
逝去的感伤 2021-01-11 14:19

I am using devise and recently added active admin, which created a separate table of admin_users to keep admins.

All works fine with Active Admin when I try to log i

相关标签:
4条回答
  • 2021-01-11 14:36

    I couldn't get @coreyward's solution to work, but editing config/application.rb as per this Devise post and adding:

    ActiveAdmin.register_page "Dashboard" do
        controller do
          skip_before_action :name_of_filter_to_skip
        end
    
        # Other code
    end
    

    to admin/dashboard.rb did the trick. It didn't work by just editing config/application.rb alone. Make sure to restart your server!

    0 讨论(0)
  • 2021-01-11 14:41

    In config/initializers/active_admin.rb you can add the following:

    config.skip_before_action :authenticate_user!
    

    You can also use the DSL provided to modify the ActiveAdmin controller: http://activeadmin.info/docs/8-custom-actions.html#modify_the_controller

    Note: For Rails versions before 5.0 you will want to use skip_before_filter.

    0 讨论(0)
  • 2021-01-11 14:50

    I couldn't make the solutions of @fringd and @coreyward to work on Rails4 (using ActiveAdmin master branch).

    So, I've moved the filter methods (I have two filters: authorize_user! and check_user_status) to a new Concern, and included this created module into the Controllers which had those filters (except for the ApplicationController, which should remain clean).

    Then restarted the server, and problem solved.

    0 讨论(0)
  • 2021-01-11 14:52

    both of the corey and Sooie are right... but only partially, to stop your blanket authorize_user! filter from affecting active_admin you need to implement both of their answers...

    config/initializers/active_admin.rb

    config.skip_before_filter :authorize_user!
    

    app/admin/dashboard.rb

    controller do
      skip_before_filter :authorize_user!
    end
    
    0 讨论(0)
提交回复
热议问题