# Link\_to within :flash

**URL:** <https://www.ruby-forum.com/t/link-to-within-flash/53093>\
**Category:** Rails\
**Created:** [January 25, 2006, 2:10am UTC](https://www.ruby-forum.com/t/link-to-within-flash/53093 "2006-01-25T02:10:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johanati](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@johanati](https://www.ruby-forum.com/u/johanati)\
**Post date:** [January 25, 2006, 2:10am UTC](https://www.ruby-forum.com/t/link-to-within-flash/53093/1 "2006-01-25T02:10:48Z")

</div>

Is there any way to use a link\_to method within a controller through a  
:flash notice? If a user enters an incorrect username/password, I want  
to have a link to a forgotten password form readily available.

My newbie attempt at doing this resulted in the following error:

undefined method `link\_to’ for #UserController:0x386aef8

I suppose I could easily have a normal link, was just wondering if there  
was a more correct way to do this.

---

<div class="post-metadata">

**Author:** ![johanati](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@johanati](https://www.ruby-forum.com/u/johanati)\
**Post date:** [January 25, 2006, 2:16am UTC](https://www.ruby-forum.com/t/link-to-within-flash/53093/2 "2006-01-25T02:16:16Z")

</div>

Have you tried something like:

session[:flash] = “blah blah blah some text #(link\_to “my link”  
:controller =\> ‘hi’, :action =\> ‘there’} some more text”

-Will

---

<div class="post-metadata">

**Author:** ![johanati](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@johanati](https://www.ruby-forum.com/u/johanati)\
**Post date:** [January 25, 2006, 2:27am UTC](https://www.ruby-forum.com/t/link-to-within-flash/53093/3 "2006-01-25T02:27:49Z")

</div>

Will B. wrote:

> Have you tried something like:
> 
> session[:flash] = “blah blah blah some text #(link\_to “my link”  
> :controller =\> ‘hi’, :action =\> ‘there’} some more text”
> 
> -Will

I tweaked that a little to get rid of the syntax errors to be:  
flash[:notice] = “blah blah blah some text #{link\_to ‘my link’,  
:controller =\> ‘hi’, :action =\> ‘there’} some more text”

The same error appears though. Even simplifying the whole thing down to:  
flash[:notice] = link\_to ‘my link’, :controller =\> ‘hi’, :action =\>  
‘there’

Still throws the same error…

---

<div class="post-metadata">

**Author:** ![johanati](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@johanati](https://www.ruby-forum.com/u/johanati)\
**Post date:** [January 25, 2006, 2:37am UTC](https://www.ruby-forum.com/t/link-to-within-flash/53093/4 "2006-01-25T02:37:31Z")

</div>

Managed to work this one out. For anyone that comes across this in the  
future, use url\_for, eg: url\_for :controller =\> ‘user’, :action =\> ‘new’

The full line is below, not sure if this will display correctly:

flash[:notice] = “\<a href=”"#{url\_for :controller =\> ‘user’, :action =\>  
‘new’}""\>test"
