Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip pundit scope on one controller

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?

like image 666
MechDog Avatar asked Sep 03 '14 18:09

MechDog


2 Answers

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
like image 148
MechDog Avatar answered Dec 19 '22 08:12

MechDog


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

like image 31
Tim Krins Avatar answered Dec 19 '22 09:12

Tim Krins