Mik*_*ren 4 timeout ruby-on-rails devise cancan ruby-on-rails-4
我有一个Rails4应用程序,我试图在会话因不活动而超时时刷新自定义消息.
我这样做是通过配置以下timeout_in设置devise.rb:
Devise.setup do |config|
...
config.timeout_in = 30.minutes
...
end
Run Code Online (Sandbox Code Playgroud)
并向我的应用程序控制器添加自定义救援:
rescue_from CanCan::AccessDenied do |exception|
if user_signed_in?
flash.now.alert = exception.message
render text: '', layout: true, status: 403
else
redirect_to new_user_session_path, notice: flash[:alert] || "You must login first"
end
end
Run Code Online (Sandbox Code Playgroud)
一切似乎工作正常...当会话超时时,flash[:alert]已经有正确的消息,所以我只是使用它,当用户尝试访问资源而不先登录然后返回"你必须先登录"消息.
这是main.html.haml页面中呈现这些警报的代码:
.container
.main-content
#flash
- flash.each do |type, msg|
%div{class: ('alert alert-dismissable fade in')}
%button.close{data: {dismiss: :alert}} ×
= msg
= yield
Run Code Online (Sandbox Code Playgroud)
问题是,有一段时间我看到一个闪烁,文本"True"出现在会话超时消息的正下方:

我无法弄清楚它来自哪里.似乎有些东西正在创建具有该值的flash消息.我想知道我做错了什么或者是否有更好的方法来显示会话超时消息.有任何想法吗?
我知道这是一个迟到的回复,但这就是我所做的.
flash.each do |type, message|
unless type.to_s == 'timedout'
<!-- Carry on printing messages -->
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1136 次 |
| 最近记录: |