Pundit::AuthorizationNotPerformedError in Rails
Asked Answered
P

1

15

screenshot

What might be causing this error in verify_authorized method and how to fix it?

Poppas answered 28/1, 2016 at 20:31 Comment(0)
I
26

Pundit adds a method to your controller called verify_authorized that ensures that the authorize method is called somewhere in your controller action. You likely setup an after_action that calls verify_authorized (https://github.com/elabs/pundit#ensuring-policies-and-scopes-are-used). Make sure you're calling authorize in each possible execution path through your controller action.

Alternatively, if you do not want to authorize that particular action, you can skip it:

class PagesControler < ApplicationController
  include Pundit
  after_action :verify_authorized, except: [:home]

  ...
end

or if you setup the after_action in an inherited controller:

class ApplicationController < ActionController::Base
  include Pundit
  after_action :verify_authorized

  ...
end

class PagesControler < ApplicationController
  skip_after_action :verify_authorized, only: [:home]

  ...
end
India answered 9/3, 2016 at 12:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.