diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 096e334..ffcfe1a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,17 +3,14 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - # config/initializers/pundit.rb - # Extends the ApplicationController to add Pundit for authorization. - # Modify this file to change the behavior of a 'not authorized' error. - # Be sure to restart your server when you modify this file. - module PunditHelper - extend ActiveSupport::Concern + if (Rails.env.development? || Rails.env.test?) + # https://github.com/RailsApps/rails-devise-pundit/issues/10 + include Pundit + # https://github.com/elabs/pundit#ensuring-policies-are-used + #after_action :verify_authorized, except: :index + #after_action :verify_policy_scoped, only: :index - #included do - #include Pundit - #rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized - #end + rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized private @@ -22,6 +19,4 @@ class ApplicationController < ActionController::Base redirect_to (request.referrer || root_path) end end - - ApplicationController.send :include, PunditHelper end diff --git a/config/initializers/pundit.rb b/config/initializers/pundit.rb index bee953c..c1c4461 100644 --- a/config/initializers/pundit.rb +++ b/config/initializers/pundit.rb @@ -7,6 +7,9 @@ module PunditHelper included do include Pundit + # https://github.com/elabs/pundit#ensuring-policies-are-used + #after_filter :verify_authorized, except: :index + #after_filter :verify_policy_scoped, only: :index rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized end @@ -18,4 +21,4 @@ module PunditHelper end end -ApplicationController.send :include, PunditHelper +ApplicationController.send :include, PunditHelper unless (Rails.env.development? || Rails.env.test?)