Use link_to in a controller?

Hello.

I realize that link_to is a helper that generally only has use in a
view file, but recently I have come across a situation where it would
be useful in a controller. I am trying to create a flash[:notice] and
I want to link to another page. Of course, I could hard code the HTML,
but for the sake of consistency, I was wondering if there is a way to
abstract it from within the controller (link_to is not accessible
there).

Thanks!

Michael S.

But I only want to have the user to have the option of visiting the
link. I am already using redirect_to() to go to the user’s account
homepage, but I am using flash[:notice] to display a message saying
that the modification was successful and because they made it, they
can do X by clicking here.

Use redirect_to.
http://api.rubyonrails.com/classes/ActionController/Base.html#M000209

Cheers,
ioana k&a
http://boulangerie.wordpress.com/

Hello Michael,

2006/6/27, Michael S. [email protected]:

But I only want to have the user to have the option of visiting the
link. I am already using redirect_to() to go to the user’s account
homepage, but I am using flash[:notice] to display a message saying
that the modification was successful and because they made it, they
can do X by clicking here.

You can use #url_for which will give you the full URL. Then, you’ll
have to code the anchor link yourself. Alternatively, use a named
action which you’ll render as a string, and then copy the resulting
text to flash[:notice].

Finally, you could Textilize your Flash messages, and use the Flash
way of generating links in your [:notice] message.

Hope that helps !

Hello,

Yep, I suppose url_for() would work as well. Hadn’t though of that,
thanks! =)

Michael S.

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