在我的 rails 3 应用程序中,我使用的是 devise 3.2.4 和 cancancan 1.9.2。我的问题是关于可以正常工作的可超时设计模块,但我无法挽救正确的异常,以便我可以向用户显示正确的通知。
我的application_controller.rb包含:
rescue_from Exception do |exception|
unless Rails.env.production?
raise exception
else
redirect_to :back, :flash => { :error => exception.message }
end
end
# https://github.com/ryanb/cancan/wiki/exception-handling
rescue_from CanCan::AccessDenied do |exception|
flash[:error] = exception.message
respond_to do |wants|
wants.html { redirect_to main_app.root_url }
wants.js { render :file => "shared/update_flash_messages" }
end
end
每当会话到期时,我都可以CanCan::AccessDenied
使用消息挽救一个通用异常您无权访问此页面,但我想捕获一个可超时的设计(我猜)异常,以便我可以显示默认的设计消息:您的会话已过期. 请重新登录以继续
任何想法?