# Possible to set flash within link\_to?

**URL:** <https://www.ruby-forum.com/t/possible-to-set-flash-within-link-to/178767>\
**Category:** Rails\
**Created:** [November 11, 2009, 2:06am UTC](https://www.ruby-forum.com/t/possible-to-set-flash-within-link-to/178767 "2009-11-11T02:06:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr\_november](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@mr\_november](https://www.ruby-forum.com/u/mr_november)\
**Post date:** [November 11, 2009, 2:06am UTC](https://www.ruby-forum.com/t/possible-to-set-flash-within-link-to/178767/1 "2009-11-11T02:06:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mr\_november](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@mr\_november](https://www.ruby-forum.com/u/mr_november)\
**Post date:** [November 11, 2009, 3:16am UTC](https://www.ruby-forum.com/t/possible-to-set-flash-within-link-to/178767/2 "2009-11-11T03:16:27Z")

</div>

On Nov 10, 5:06 pm, Arif B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

---

<div class="post-metadata">

**Author:** ![mr\_november](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@mr\_november](https://www.ruby-forum.com/u/mr_november)\
**Post date:** [November 11, 2009, 8:03pm UTC](https://www.ruby-forum.com/t/possible-to-set-flash-within-link-to/178767/3 "2009-11-11T20:03:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mr\_november](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f0a364/32.png) [@mr\_november](https://www.ruby-forum.com/u/mr_november)\
**Post date:** [November 11, 2009, 10:47pm UTC](https://www.ruby-forum.com/t/possible-to-set-flash-within-link-to/178767/4 "2009-11-11T22:47:44Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
