ruby on Rails 闪存消息 - :alert :error :notice 和 :success?
在我的几个控制器中,我有重定向/闪现消息
redirect_to products_url, :notice => "message here",
redirect_to states_url, :error => "oops!" etc...
在我的会话控制器中,但是,在成功验证后,我有 flash[:成功] = "欢迎!" redirect_to user
我希望能够在我的其他控制器中执行类似的操作 :成功=> “耶!”
这主要是为了美观/一致性的目的,但是 :notice、:alert 和 :error 是唯一可用的 flash 类型/我可以添加其他类型吗?我说得有道理吗?
谢谢!
In several of my controllers, I have redirects/flash messages
redirect_to products_url, :notice => "message here",
redirect_to states_url, :error => "oops!" etc...
In my sessions controller, however, upon successful authentication, I have
flash[:success] = "welcome!"
redirect_to user
I'd like to be able in my other controllers to do something like
:success => "yay!"
This is mostly for cosmetic/consistency purposes, but are :notice, :alert and :error the only flash-types available / can I add additional types? Am I making sense?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信,如果不进行更改,这将是您所得到的最接近的结果:
这里有一些 有关友好 Flash 语法添加的附加说明。
I believe without changes, this is as close as you'll get:
Here's some additional notes regarding the friendly flash syntax addition.
我刚刚发现在 Rails 4 中你可以在应用程序控制器中注册自定义类型:
优点是 http://blog.remarkablelabs.com/2012/ 12/注册您自己的 flash-types-rails-4-2013 年倒计时
I just found out that in Rails 4 you can register custom types in app controller:
The merit goes to http://blog.remarkablelabs.com/2012/12/register-your-own-flash-types-rails-4-countdown-to-2013
如果您想基于引导警报(成功和警告)访问不同类型的闪存消息样式,请在控制器中:
在布局中(最有可能是 application.html.erb)
与警告和其他引导警报样式相同。
If you want to access different types of flash messages styles based on bootstrap alert (success and warning), in you controller:
And in your layout (most probably application.html.erb)
Same thing with warning and other bootstrap alert styles.