Rails:redirect_to with :error,但 flash[:error] 为空 [英] Rails: redirect_to with :error, but flash[:error] empty

查看:34
本文介绍了Rails:redirect_to with :error,但 flash[:error] 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在设置 flash[:error] 值时进行重定向.(Rails 3.0.10)

I'm trying to do a redirect while setting the flash[:error] value. (Rails 3.0.10)

在我看来我有

<p id="error"><%= flash[:error] %></p>
<p id="notice"><%= flash[:notice] %></p>

如果我执行 redirect_to show_path,:notice =>"ok" 它工作正常,但如果我执行 redirect_to show_path, :error =>错误"它没有出现.

If I do a redirect_to show_path, :notice => "ok" it works fine, but if I do redirect_to show_path, :error => "error" it doesn't show up.

我会错过什么?

推荐答案

中所述Rails API 仅 :notice 和 :alert 默认情况下作为 flash 哈希值应用.如果你需要设置 :error 值,你可以这样做:

As stated in the Rails API only :notice and :alert are by default applied as a flash hash value. If you need to set the :error value, you can do it like this:

redirect_to show_path, flash: { error: "Insufficient rights!" }

这篇关于Rails:redirect_to with :error,但 flash[:error] 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆