我更新到Rails 2.3.10,Rack 1.2.1,现在我的flash消息都没有出现.我发现在重定向期间,通知会像这样传递
redirect_to(@user,:notice => "Sorry there was an error")
在我看来,flash哈希是空的
<%= debug flash %> !map:ActionController::Flash::FlashHash {}
但是您可以在控制器中看到该消息.是什么赋予了?
<%= debug controller.session %> session{:home_zip=>"94108",:session_id=>"xxx",:flash=>{:notice=>"Sorry there was an error"},:user_credentials=>"1baf9c9c0423ce0151ec32e24cc422f07309e4ba503eb4830635ecc115da217809997324374bb273b3fb792895c9741a8b8c9ea4267771a1bd149de5b9179ea0",:user_credentials_id=>22,:home_market_id=>11} Edit Profile
解决方法
我们也碰到了这个.我们所有的Flash消息都会通过重定向消失,但不会在控制器中明确设置时消失.
不起作用:
def create if @obj.save flash[:notice] = "The #{cname.humanize.downcase} has been created." redirect_back_or_default redirect_url else render :action => 'new' end end
这确实有效:
def show @user = current_user flash[:notice] = "Hello -- this will show up fine" end