makes cancan return a json error when asked for json and permissions fail

This commit is contained in:
kikito
2015-12-16 14:02:03 +01:00
parent 5607f0f86a
commit 7996f5f816

View File

@@ -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