(Rails 1.1, Ruby 1.8.4) In the layout for one of my controllers, I have a tag to display a flash message (copied from AWDWR), like this: <div id="data"> <% if @flash[:notice] -%> <div id="notice"><%= @flash[:notice] %></div> <% end -%> <%= @content_for_layout %> </div> If the controller sets the message, it is displayed as expected: so far so good. But if I then navigate to a different action of the same controller, the flash isn''t cleared, where I thought it was supposed to be cleared out automatically when the current rendering was complete. On the second subsequent call to the same controller it does disappear. If I clear it manually after displaying it, as follows, then all is well. <% @flash[:notice] = nil; end -%> So I have a work-around, but can anyone help me understand what is going on: am I doing something wrong, or misunderstanding how the flash is meant to work? Thanks in advance Bill -- Posted via http://www.ruby-forum.com/.
i am having the same problem. Are you using the db to store your sessions? I started noticing this problem when i switched from file storage to database storage. I dont know if it makes a difference or why it should matter at all. Can anyone shed some more light here? On 6/1/06, Bill <bill.roberts@planet.nl> wrote:> > (Rails 1.1, Ruby 1.8.4) > > In the layout for one of my controllers, I have a tag to display a flash > message (copied from AWDWR), like this: > > <div id="data"> > <% if @flash[:notice] -%> > <div id="notice"><%= @flash[:notice] %></div> > <% end -%> > <%= @content_for_layout %> > </div> > > If the controller sets the message, it is displayed as expected: so far > so good. > > But if I then navigate to a different action of the same controller, the > flash isn''t cleared, where I thought it was supposed to be cleared out > automatically when the current rendering was complete. On the second > subsequent call to the same controller it does disappear. > > If I clear it manually after displaying it, as follows, then all is > well. > > <% @flash[:notice] = nil; end -%> > > So I have a work-around, but can anyone help me understand what is going > on: am I doing something wrong, or misunderstanding how the flash is > meant to work? > > Thanks in advance > > Bill > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Manish Shah www.rapleaf.com SkypeIn: +1 (415) 578-4485 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060602/8e190002/attachment.html
Bill wrote:> (Rails 1.1, Ruby 1.8.4) > So I have a work-around, but can anyone help me understand what is going > on: am I doing something wrong, or misunderstanding how the flash is > meant to work? > > Thanks in advance > > BillThe flash is meant to display something in next action, not the current one. It is cleared in the request after it is created For example: def create @foo = Foo.new(params[:foo]) if @foo.save flash[:notice] = ''Foo was created successfully'' redirect_to :action => ''show'', :id => @foo.id else render :action => ''new'' end end Now when the user submits valid data for a "foo" the flash says confirms everthing went smooth, and the browser is redirected to make a new request, where the flash is displayed. If you do a flash without a redirect, you will see the flash on the current page you just rendered AND the next page, and then it should be cleared. For this reason flash should primarily be used with redirect. -- Posted via http://www.ruby-forum.com/.
I am using flash with redirects. However its not being cleared. I cant tell whats going on. On 6/2/06, Alex Wayne <rubyonrails@beautifulpixel.com> wrote:> > Bill wrote: > > (Rails 1.1, Ruby 1.8.4) > > So I have a work-around, but can anyone help me understand what is going > > on: am I doing something wrong, or misunderstanding how the flash is > > meant to work? > > > > Thanks in advance > > > > Bill > > The flash is meant to display something in next action, not the current > one. It is cleared in the request after it is created > > For example: > > def create > @foo = Foo.new(params[:foo]) > if @foo.save > flash[:notice] = ''Foo was created successfully'' > redirect_to :action => ''show'', :id => @foo.id > else > render :action => ''new'' > end > end > > Now when the user submits valid data for a "foo" the flash says confirms > everthing went smooth, and the browser is redirected to make a new > request, where the flash is displayed. > > If you do a flash without a redirect, you will see the flash on the > current page you just rendered AND the next page, and then it should be > cleared. > > For this reason flash should primarily be used with redirect. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Manish Shah www.rapleaf.com SkypeIn: +1 (415) 578-4485 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060602/b95e7861/attachment-0001.html
On 6/2/06, Manish Shah <mnshah@gmail.com> wrote:> I am using flash with redirects. However its not being cleared. I cant > tell whats going on. > > On 6/2/06, Alex Wayne < rubyonrails@beautifulpixel.com> wrote: > > The flash is meant to display something in next action, not the current > > one. It is cleared in the request after it is createdI''ve found that redirects from a before_filter don''t affect the flash, i.e. it stays for the next two requests. Perhaps you have the same issue, and is this working as intended? I fix this using flash.now instead of just flash in the filter. HTH, Isak
Hi, This was *exactly* my problem. It was driving me _insane_. Thank you so much for pointing it out! Merc. Isak Hansen wrote:> On 6/2/06, Manish Shah <mnshah@gmail.com> wrote: >> I am using flash with redirects. However its not being cleared. I cant >> tell whats going on. >> >> On 6/2/06, Alex Wayne < rubyonrails@beautifulpixel.com> wrote: >> > The flash is meant to display something in next action, not the current >> > one. It is cleared in the request after it is created > > I''ve found that redirects from a before_filter don''t affect the flash, > i.e. it stays for the next two requests. > Perhaps you have the same issue, and is this working as intended? > > I fix this using flash.now instead of just flash in the filter. > > HTH, > Isak-- Posted via http://www.ruby-forum.com/.