I have a specific application helper do display all my flash messages ( according to my css ) def flash_messages result ="" %w(notice warning error alert).each do |msg| # change skin labels box = "info_box" if msg == "notice" box = "tip_box" if msg == "warning" box = "error_box" if msg == "error" box = "error_box" if msg == "alert" result << content_tag(:div, content_tag(:p, flash.now[msg.to_sym]), :class => "#{box}") unless flash[msg.to_sym].nil? end result.html_safe end and I use <%= flash_messages %> to display the flash[:error] when rendering again the :new action this is working fine,.. however in the form , I have a link to go back to the :index page upon the index page display , the flash[:error] is not cleared.. ( it will if I add flash[:error] = nil? in my index action before rendering... I thought that : flash.now[msg.to_sym]) would be enough .. but seems not to be the case any clue ? thanks -- 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.
Jim Ruther Nill
2012-Jan-18 13:25 UTC
Re: using a link in a view , flash message doesn''t clear
On Wed, Jan 18, 2012 at 7:23 PM, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> wrote:> I have a specific application helper do display all my flash messages > ( according to my css ) > > def flash_messages > result ="" > %w(notice warning error alert).each do |msg| > # change skin labels > box = "info_box" if msg == "notice" > box = "tip_box" if msg == "warning" > box = "error_box" if msg == "error" > box = "error_box" if msg == "alert" > result << content_tag(:div, content_tag(:p, > flash.now[msg.to_sym]), :class => "#{box}") unless > flash[msg.to_sym].nil? > end > result.html_safe > end > > and I use <%= flash_messages %> to display the flash[:error] when > rendering again the :new action > this is working fine,.. however in the form , I have a link to go back > to the :index page > upon the index page display , the flash[:error] is not cleared.. ( it > will if I add flash[:error] = nil? in my index action before > rendering... > > I thought that : flash.now[msg.to_sym]) would be enough .. but seems > not to be the case > > any clue ? thanks > >The helper doesn''t have anything to do with the problem. In your controllers, make sure that you''re using flash.now if you''re rendering a template and flash if redirecting. So I think you have something like flash[:error] = ''Error!'' render :new in your controller. Change flash to flash.now and it should work.> -- > 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. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- 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.
Thanks a lot Jim ... I forgot it ... :-(( On Jan 18, 2:25 pm, Jim Ruther Nill <jvn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Jan 18, 2012 at 7:23 PM, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > I have a specific application helper do display all my flash messages > > ( according to my css ) > > > def flash_messages > > result ="" > > %w(notice warning error alert).each do |msg| > > # change skin labels > > box = "info_box" if msg == "notice" > > box = "tip_box" if msg == "warning" > > box = "error_box" if msg == "error" > > box = "error_box" if msg == "alert" > > result << content_tag(:div, content_tag(:p, > > flash.now[msg.to_sym]), :class => "#{box}") unless > > flash[msg.to_sym].nil? > > end > > result.html_safe > > end > > > and I use <%= flash_messages %> to display the flash[:error] when > > rendering again the :new action > > this is working fine,.. however in the form , I have a link to go back > > to the :index page > > upon the index page display , the flash[:error] is not cleared.. ( it > > will if I add flash[:error] = nil? in my index action before > > rendering... > > > I thought that : flash.now[msg.to_sym]) would be enough .. but seems > > not to be the case > > > any clue ? thanks > > The helper doesn''t have anything to do with the problem. In your > controllers, > make sure that you''re using flash.now if you''re rendering a template and > flash > if redirecting. So I think you have something like > > flash[:error] = ''Error!'' > render :new > > in your controller. Change flash to flash.now and it should work. > > > -- > > 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. > > -- > ------------------------------------------------------------- > visit my blog athttp://jimlabs.heroku.com-- 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.