Does a request and the request created by a "link_to 'xxx', {:action => 'xx'} :popup => true " share flash?

I have a url called A, in its resource , this exists:
  <%= link_to 'XXX', {:action => 'xxx'}, :popup => true %>
and I click it and create a new request with url B
Now I have two requests, or two browser pages A and B
I click a submit button in B, it dose something back and show a Tip
"Save correctly!" in top of B
and I turn to A, and REFRESH it , and I see the same tip "Save
correctly!" in top of A!
in back end, I store the tip with flash[:notice]
So it seems they share the flash, between requests !
Can anyone tells me why ?
or tell me where i can find the answer.

I usually use it :

class ApplicationController < ActionController::Base

  def reset_notice
    flash[:notice] = nil
  end

end

class MyRails < ApplicationController
before_filter :reset_notice

...

end

Hope it's helpful.

Visit Indonesia 2008 wrote:

I usually use it :

class ApplicationController < ActionController::Base

  def reset_notice
    flash[:notice] = nil
  end

end

class MyRails < ApplicationController
before_filter :reset_notice

...

end

Hope it's helpful.

~*~*~*~**~*~*~*~*~*~*~*~
Reinhart Ariand
YM : Booking2Heaven
WEB: teapoci.blogspot.com
~*~*~*~**~*~*~*~*~*~*~*~

This will clear the flash container every time but sometimes you don't
WANT this to happen. (You're overriding the default behaviour of the
flash mechanism this way)

If you do want a messages to last only for the life of the current
request try this:

flash.now[:notice] = "message"

In the original post above it would show only for the submission of B
but the refresh of A would not show the message.

Hope this helps.

ohh.. sorry. I did miss understood. Next time i will read careful the
posting.

Thank you~
en, I have just learn the default behavior of the flash, i am
confused...
some guy says "Flash--Communicating between Actions"
I thought flash is just a pre-defined hash between action and its view
Can anyone tells me more details ? Or tell me where I can find the
precise answer
Thanks~
Jean Nibee wrote:

Thank you all the same ~~

Thank you~
en, I have just learn the default behavior of the flash, i am
confused...
some guy says "Flash--Communicating between Actions"
I thought flash is just a pre-defined hash between action and its view
Can anyone tells me more details ? Or tell me where I can find the
precise answer

the flash is suppose to persist to the next request (but only the next
request). If you set flash.now[:notice] = ...
Then it won't persist to the next request.

Fred

Thank you~~
So an usual usage may be:
def A
  flash[:notice] = "I came from ActionName A"
  redirect_to :action => B
end
am I right?

You can not display that flash[:notice] on :action B because action B
doesnt have params of your notice. Try this maybe help you:

  def A
   session[:notice] = "I came from ActionName A"
   redirect_to :action => B
#that notice can be displayed only if you do render :action => B
  end

  def B
   flash[:notice] = session[:notice]
  end

Really? I doubt it !
render :action => B means "Use action B's view as this action's view",
not means "start a new request to B"
and in this way you just change your default view, not a "next
request"
see this from http://api.rubyonrails.org/
"
  # Renders the template for the action "goal" within the current
controller
  render :action => "goal"
"
"
  the flash is suppose to persist to the next request (but only the
next
  request). If you set flash.now[:notice] = ...
  Then it won't persist to the next request.
"
And as I said before, it's true that the "redirect_to" request acts as
"the next request", and do get the flash content.
For this, use below for test:
"
     def a
    flash[:a] = "I am a"
    #render :action => 'b'
    redirect_to :action => 'b'
  end

  def b
    if flash[:a].blank?
       flash[:a] = "I am b"
    end
    render :text => flash[:a]
  end
"
It seems "link_to" request 's parent request, I mean the request which
has a "link_to" tag, will act as "the next request" as I mentioned in
the first reply
Next request ? What actually does next request mean ?
Can anyone give a precise definition?
Can anyone give example-usage for flash ?

redirect_to is the same like link_to in view, if your action 'A'
redirect to another action 'B', all params in A are unreadable in 'B'
unless you including params behind of :action or store in in session.

render what i mean is using all logics in def B but you will use A.rhtml
to display all logics in B & A.

I think you are wrong, at least in rails 2.0.2
render to B in action A means using only logics in A and B.rhtml
just this.
You can test this in rails 2.0.2
or read the api : http://api.rubyonrails.org/classes/ActionController/Base.html#M000452
I thought the same as you when I was using rails 1.8 or before.

You can not display that flash[:notice] on :action B because action B
doesnt have params of your notice. Try this maybe help you:

Um bollocks. the flash is actually stored in the session anyway, so
the code below accomplishes nothing more than setting flash[:notice].
If you were to use render :action => B then you should use
flash.now[:notice] = 'hello', so that the flash does not persist to
the request after (but in your view you still access it as
flash[:notice]

Fred