我正在控制器中进行一些异常处理,当:create操作中引发异常时,我将呈现为:new操作并显示一条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
我的布局代码(Haml):
%body
#content
- unless flash[:alert].blank?
#alert= flash[:alert]