Bug fix for Guard/Spring/Pundit https://github.com/RailsApps/rails-devise-pundit/issues/10
This commit is contained in:
parent
a23e58f292
commit
69f57f940e
@ -2,4 +2,26 @@ class ApplicationController < ActionController::Base
|
|||||||
# Prevent CSRF attacks by raising an exception.
|
# Prevent CSRF attacks by raising an exception.
|
||||||
# For APIs, you may want to use :null_session instead.
|
# For APIs, you may want to use :null_session instead.
|
||||||
protect_from_forgery with: :exception
|
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
|
||||||
|
|
||||||
|
#included do
|
||||||
|
#include Pundit
|
||||||
|
#rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
||||||
|
#end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def user_not_authorized
|
||||||
|
flash[:alert] = 'Access denied.'
|
||||||
|
redirect_to (request.referrer || root_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ApplicationController.send :include, PunditHelper
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user