Rails3.0.3, Controller:Method update: 1. Redirect to Show, flash is shown, works format.html { redirect_to(@article, :notice => ''Article was successfully saved.'') } 2- Redirect to Edit, flash is shown, works format.html { flash[:notice] = ''Article was successfully saved.'' redirect_to(:action => ''edit'') } 3. Redirect to Edit, flash is NOT shown format.html { redirect_to(:action => ''edit'', :notice => ''Article was successfully saved.'') } The flash is in application.html.erb: <section id="content"> <section id="flash"> <% flash.each do |key, value| %> <div class="flash <%= key %>"><%= value %></div> <% end %> </section> <%= yield %> </section> Can someone explain this behaviour to me? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Jan-08 13:13 UTC
Re: Flash :notice in redirect_to not working in some cases?
On Jan 8, 12:56 pm, bourne <bour...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Rails3.0.3, Controller:Method update: > > 1. Redirect to Show, flash is shown, works > format.html { > redirect_to(@article, :notice => ''Article was successfully > saved.'') > } > > 2- Redirect to Edit, flash is shown, works > format.html { > flash[:notice] = ''Article was successfully saved.'' > redirect_to(:action => ''edit'') > } > > 3. Redirect to Edit, flash is NOT shown > format.html { > redirect_to(:action => ''edit'', :notice => ''Article was > successfully saved.'') > } > > Can someone explain this behaviour to me?In the third case, rails thinks that :notice is part of the routing options - you can probably see that the url redirected to has ? notice=... on it. Ruby can''t know that the first bit is for the routing options has and that the second bit is for the other options hash. On the other hand, in the first case it is unambiguous Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.