Skip authorization for specific controllers using pundit in rails 4

I use rails 4, create for authentication and Pundit for authorization. I limited my application to authorization checks on each controller using the code below.

class ApplicationController < ActionController::Base
  include Pundit
  after_action :verify_authorized
  #.....
end

However, I want to skip authorization for two specific controllers in my application (they are open to the public, users do not need to log in). How can I achieve this without removing verify_authorized in ApplicationController?

+4
source share
2 answers

skip_after_action :verify_authorized

+7
source

Rails 5, , . , , skip_authorization , :

class Admin::DashboardController < Admin::BaseController
    def index
        @organizers = Organizer.count
        @sponsors = Sponsor.count
        @brochures = Brochure.count

        skip_authorization
    end

    def sponsors_approve
        # some statements...
    end

    def organizers_approve
        # some statements...
    end
end

, , index, .

, - .

+1

Source: https://habr.com/ru/post/1589521/


All Articles