Skip pundit scope on one controller
Asked Answered
L

2

6

I want to skip the policy_scope requirement fro Pundit on one controller (home). I have tried this:

 class ApplicationController < ActionController::Base
  include Pundit
  after_action :verify_authorized, :except => :index, unless: :devise_controller?
  after_action :verify_policy_scoped, :only => :index, unless: controller.controller_name == "home"
 end

 class HomeController < ApplicationController
   def index
     redirect_to (new_user_session_path) unless user_signed_in?
     if user_signed_in?
       @user=current_user
     end
    end
  end

But I don't think the controller is defined yet or something? Any thoughts or suggestions?

Lohner answered 3/9, 2014 at 18:20 Comment(0)
L
8

I accomplished this by adding a skip_after_action to the home controller:

class HomeController < ApplicationController
  skip_after_action :verify_policy_scoped, :only => :index
end
Lohner answered 3/9, 2014 at 18:44 Comment(0)
B
6

Since version 1.0.0 you can use skip_policy_scope in a controller action.

Bipack answered 8/3, 2019 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.