Link_to within :flash

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.

Have you tried something like:

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

-Will

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…

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"

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs