views:

197

answers:

2

I want links that when hovered over you see the link to look something like this:

http://www.website.com/redirct_to=linkID2 (maybe not exactly like that but try to get the idea)

I have a form area in my blog that I can input a website url but I want to make it redirect_to an external website when it shows the post.

+1  A: 

Create a new model, for example called Link, to store the URLs you want to redirect to. Then generate a new controller (you can use scaffold to generate controller and model at the same time) and change the show action in order to fetch the record with given ID and redirect_to @link.url.

If you don't want to use the #show action for this step, create a new action do handle the redirect (for example goto, redirect...).

Simone Carletti
+7  A: 
redirect_to url

should do it as long as protocol is included. For added flexibility, you can parse it with URI to ensure that all fields are correct. You might want to URI.encode/URI.decode

Ben Hughes
I'm looking this to work<%= redirect_to(post.link_url) %> I tried this a few different ways.All I get undefined method `redirect_to' when I try that.
Aaron
put it in a controller action. It is not something you can do from a view (well should not, if you must do it from a view, use `<%= javascript_tag("window.location=#{url}") %>`
Ben Hughes