【问题标题】:Flash[:warning] not working with redirectFlash[:warning] 不适用于重定向
【发布时间】:2013-01-31 11:16:33
【问题描述】:

我使用 flash[:notice] 显示成功消息,使用 flash[:warning] 显示警告和错误消息。

即使在重定向到另一个页面时,Flash[:notice] 也可以正常工作,但 flash[:warning] 不能用于重定向。

当我签入我的视图文件时,flash[:warning] 作为 nil 传递。

如何将 flash[:warning] 与 redirect_to 一起使用?

【问题讨论】:

  • 使用 flash[:error] 警告/错误
  • 问题是我使用 flash[:notice] 来显示绿色的 flash 消息和 flash[:error] 来显示红色的 flash 消息和 flash[:warning] 来显示 flash 消息橙色。我的 flash[:notice] 和 flash[:error] 工作正常,但我的 flash[:warning] 不行。
  • 你在特定视图中写过吗?

标签: ruby-on-rails flash-message


【解决方案1】:

您可以通过重定向传递闪烁使用

redirect_to 'page/to/redirect/to', :flash => { :error => 'Some error' }

【讨论】:

  • 问题是我使用 flash[:notice] 来显示绿色的 flash 消息和 flash[:error] 来显示红色的 flash 消息和 flash[:warning] 来显示 flash 消息橙色。我的 flash[:notice] 和 flash[:error] 工作正常,但我的 flash[:warning] 不行。
  • 嗯,你说通过:flash => { :warning => "some warning" } 不起作用?
  • @user001 您可能在起点-终点之间有额外的重定向,或者您正在重新分配闪存。无论如何 - 问题在于你的代码,而不是一些关于 flash 的巫术魔法。
  • 是的,我有多个重定向,那么如何让我的 flash[:warning] 与多个重定向一起工作?
猜你喜欢
  • 1970-01-01
  • 2017-08-28
  • 2012-08-20
  • 1970-01-01
  • 1970-01-01
  • 2010-12-08
  • 2021-09-25
  • 2012-03-27
  • 2013-10-31
相关资源
最近更新 更多