Take the 2-minute tour ×

I'm looking to redirect users to another website, and include their user id in the link. The problem is that the url is different for each record.

The desired URL: ..../index.php?user_id=123 In another url, it might be: ..../index.php?user=123&foo=true

The desired form entry: http://www.google.com/index.php?user_id=#{@user.id}

How would I do this?

Thanks in advance! Mitch

share|improve this question
add comment

1 Answer

Insert the ID in a normal link tag:

<a href="http://www.google.com/index.php?user_id=<%= @user.id %>">Link text</a>

Or create the link in a helper, model method, etc:

def google_url(id)

<a href="<%= google_url(@user.id) %>">Link text</a>

There are a few other options, I suppose.

share|improve this answer
How would I use this in a redirect_to @campaign.link in the controller? - because the location of the user.id is always moving, depending on the campaign/link. –  user1175331 Jan 28 '12 at 15:18
@user1175331 It's... moving? Are you asking "How do I replace a value in a string"? –  Dave Newton Jan 28 '12 at 15:24
Yep. Seems I was asking how to replace a string value. I was trying to do it immediately in the process, by using #{current_user.id}, instead of using gsub later! Fixed. Thanks so much for your help! –  user1175331 Jan 28 '12 at 15:53
add comment

Your Answer


