makes cancan return a json error when asked for json and permissions fail
This commit is contained in:
@@ -17,7 +17,10 @@ class ApplicationController < ActionController::Base
|
|||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
rescue_from CanCan::AccessDenied do |exception|
|
rescue_from CanCan::AccessDenied do |exception|
|
||||||
redirect_to main_app.root_url, alert: exception.message
|
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
|
||||||
|
|
||||||
layout :set_layout
|
layout :set_layout
|
||||||
|
|||||||
Reference in New Issue
Block a user