问题描述
在设计验证框架使用闪光灯通知无处不在。这使得它易于与应用程序集成,但它有时会导致用户体验不佳。
The Devise authentication framework uses flash notices everywhere. This makes it easy to integrate with apps but it leads to poor user experience sometimes.
我想知道什么是一个简单的方法来选择性地关闭一些设计闪光通知在我的Rails 3应用程序。我特别想摆脱公然明显signed_in和signed_out闪烁。
I am wondering what's an easy way to selectively turn off some of the Devise flash notices in my Rails 3 app. In particular, I'd like to get rid of the blatantly obvious signed_in and signed_out flashes.
一些网站的搜索建议继承会话控制器或使用something这样,但我一直没能找到任何简单的解决方案这个问题。
Some searching suggested subclassing the session controller or use something like this but I haven't been able to find any simple solutions to this problem.
推荐答案
您可以自定义的I18n后端其中制定支持您的色器件的提示信息。如果设置的没有的特定键,将不会显示空闪消息,例如用于sign_in和SIGN_OUT:
You can customize your devise flash messages with I18n backend which devise supports. If you set nothing for particular key, the empty flash message won't be shown, for example for sign_in and sign_out:
en:
devise:
failure:
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
invalid: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
sessions:
signed_in: ""
signed_out: ""
UPD。
您不能拔出钥匙,否则你会得到一个错误。
不显示空的Flash的消息,你应该做简单的检查视图(为前与HAML):
You should not remove the key otherwise you will get an error.To not display empty flash messages you should do simple check in the view (for ex. with haml):
- unless notice.blank? && alert.blank?
#flash
.wrapper
- unless notice.blank?
%p.notice= notice
- unless alert.blank?
%p.alert= alert
这篇关于在Rails 3中选择性地关闭设计的闪存通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!