我正在尝试在设置 flash[:error] 值时进行重定向。 (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 => "error"
它没有出现。
我可能会错过什么?
最佳答案
如 Rails API 中所述默认情况下,仅 :notice 和 :alert 用作闪存哈希值。如果需要设置 :error 值,可以这样做:
redirect_to show_path, flash: { error: "Insufficient rights!" }
关于ruby-on-rails-3 - Rails : redirect_to with :error, 但 flash[:error] 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7510418/