我正在我的控制器中进行一些异常处理,当抛出异常时:create action,我将渲染到:new action并显示flash消息.
一切正常,我可以在异常捕获时看到flash消息,但是当我重定向到(手动点击)其他页面时,flash消息仍然在这里.然后我重定向到另一个页面(第二次手动点击),消息可能会消失.
有谁知道是什么原因?
我的控制器代码:
class MessagesController < ApplicationController
rescue_from Exception, :with => :render_new
def new
end
def create
end
private
def render_new
flash[:alert] = t("uploading_error")
render :action => :new
end
end
Run Code Online (Sandbox Code Playgroud)
我的布局代码(Haml):
%body
#content
- unless flash[:alert].blank?
#alert= flash[:alert]
Run Code Online (Sandbox Code Playgroud) 我在Rails应用程序中使用闪存通知,使用以下代码:
flash[:notice] = "Sorry, we weren't able to log you in with those details."
render :action => :new
Run Code Online (Sandbox Code Playgroud)
Flash消息在"新"操作上按预期呈现,但随后它也会显示用户访问的下一页(无论可能是什么).它应该只显示一次,但有些东西会让它坚持下去.