问题
I am trying to find a way to display my flash errors on the active page without the redirect_to
method.
By the way, the standard flash[:alert] = exception.message
didn't show me any error messages, so I changed it to flash[:error]
.
Thanks for any advice!
rescue_from CanCan::AccessDenied do |exception|
flash[:error] = exception.message
redirect_to deadlines_path
end
回答1:
Try:
rescue_from CanCan::AccessDenied do |exception|
flash.now[:alert] = exception.message
render 'something_else'
return false
end
without a redirect.
来源:https://stackoverflow.com/questions/4767460/how-to-show-accessdenied-errors-on-the-active-page-with-cancan-in-rails3