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. -- Posted via http://www.ruby-forum.com/.
Have you tried something like: session[ :flash ] = "blah blah blah some text #(link_to "my link" :controller => ''hi'', :action => ''there''} some more text" -Will On 1/24/06, Johan Ati <johanati@gmail.com> wrote:> 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. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Will Briggs wrote:> Have you tried something like: > > session[ :flash ] = "blah blah blah some text #(link_to "my link" > :controller => ''hi'', :action => ''there''} some more text" > > -WillI 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.. -- Posted via http://www.ruby-forum.com/.
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</a>" -- Posted via http://www.ruby-forum.com/.