Possible to set flash within link_to?

hi all,

i’d like to set the flash to some text when a user clicks a link. i know
it’s possible set a random variable and then it’s available in the
params hash but is it possible to do so with the flash? or do i have to
create a new action, make the link load the action, and set the flash
there?

i want to set the flash in a link_to similar to below:
<%= (link_to “SEND”, {:controller => “company”, :action => “show”, :id
=> current_company.id}) %>

thanks.

On Nov 10, 5:06 pm, Arif B. [email protected]
wrote:

i want to set the flash in a link_to similar to below:
<%= (link_to “SEND”, {:controller => “company”, :action => “show”, :id
=> current_company.id}) %>

If a flash is set in that code snippet, I sure can’t find it.

Eric wrote:

<%= (link_to “SEND”, {:controller => “company”, :action => “show”, :id
=> current_company.id}) %>

If a flash is set in that code snippet, I sure can’t find it.

Right, thanks Eric. that’s why i’m asking the question, because i want
to know how to set the flash in the above code snippet, and therefore
add to it.

Maybe you’re right though, i should have put my half-baked attempt at
doing so in the example. However, it’s pretty clear whatever variable
you assign to in a link_to becomes available in the params hash, I don’t
see how’d you add to the flash hash.

Anyways, the temporary, possibly ugly solution, I’m using is to add a
param to the link_to, check for the param in the action, and if present,
add to the flash. If there is a better way to do it, please let me know.

Currently in view:
<%= (link_to “VIEW”, :controller => “company”, :action => “show”, :id =>
current_company.id, :output_flash => “yep”) %>

in controller, show method:
flash[:notice] = “blah blah blah” if params[:output_flash] == “yep”

thanks.

Maybe with some Javascript - link_to_remote? You could also look into
a rjs template which can modify a part of the page - an element, maybe
one named “flashing text”…

Simply Rails 2 by Patrick Lenz is a very good book which is where I
got the above info.

On Nov 10, 8:06 pm, Arif B. [email protected]