Flash notification with redirect_to railed

I updated Rails 2.3.10, Rack 1.2.1, and now none of my flash messages appear. I found that during redirection, the notification is transmitted this way

redirect_to(@user, :notice => "Sorry there was an error") 

And in my opinion the flash hash is empty

 <%= debug flash %> !map:ActionController::Flash::FlashHash {} 

But you can see the message in the controller. What gives?

  <%= 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 => {: notice => "Sorry there was an error"},: user_credentials => "1baf9c9c0423ce0151ec32e24cc422f07309e4ba503eb4830635ecc115da217809997324374bb273b3fb792895c9741a8b8c9ea4267771a1bd149de5b9179ea0",: user_credentials_id =>  <%= 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 
+6
ruby ruby-on-rails
source share
4 answers

We also encountered this. All our flash messages disappear with redirection, but not when explicitly installed in the controller.

Does not work:

  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 

It works:

  def show @user = current_user flash[:notice] = "Hello -- this will show up fine" end 
+1
source share

Have you checked the track tracker? I still use the old-fashioned setter flash[:notice] = message , and it works fine, so it seems to be a problem with the redirect_to method.

https://rails.lighthouseapp.com/

You tried to execute redirect_to url, :flash => { :notice => "notice" } , how does it work?

+4
source share

The code below should work:

redirect_to(@user, {:notice => "Sorry there was an error"})

I suppose this is due to changes in Ruby, not Rails, because it is like changing the priority of a token in the compiler.

+4
source share

This could be a cookie problem. In short, cookies are not received if you redirect immediately afterwards. Assuming that Rails implements flash using cookies, redirecting is your problem.

Sources:

http://persistall.com/archive/2008/01/25/cookies--redirects--nightmares.aspx http://stackoverflow.com/questions/1621499/why-cant-i-set-a-cookie-and -redirect

+1
source share

All Articles