Files
grecia/app/controllers/concerns/access_denied_handler.rb
Javi Martín 286e0ca878 Handle AccessDenied in management sessions
We were raising a `CanCan::AcessDenied` and were getting a 500 Internal
Server Error.

I've chosen to do the same thing we do in the ApplicationController.
There are other options to handle this request, like redirecting to the
login page or returning a 401 Unauthorized HTTP status.
2019-04-25 20:36:50 +02:00

13 lines
349 B
Ruby

module AccessDeniedHandler
extend ActiveSupport::Concern
included do
rescue_from CanCan::AccessDenied do |exception|
respond_to do |format|
format.html { redirect_to main_app.root_url, alert: exception.message }
format.json { render json: { error: exception.message }, status: :forbidden }
end
end
end
end