# Advanced routing question

**URL:** <https://www.ruby-forum.com/t/advanced-routing-question/50284>\
**Category:** Rails\
**Created:** [December 14, 2005, 8:58pm UTC](https://www.ruby-forum.com/t/advanced-routing-question/50284 "2005-12-14T20:58:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aantix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f0a364/32.png) [@aantix](https://www.ruby-forum.com/u/aantix)\
**Post date:** [December 14, 2005, 8:58pm UTC](https://www.ruby-forum.com/t/advanced-routing-question/50284/1 "2005-12-14T20:58:39Z")

</div>

Hello All,

I’m making a quick application that tracks outgoing links to referral  
sites. I need to track the user and the url they went to so the  
easiest way would be to take the entire url as a parameter and log  
that into the database. I was wondering if I could do something like  
this with routing:

[http://www.example.com/user/jump/http://www.myvendor.com/referral.php](http://www.example.com/user/jump/http://www.myvendor.com/referral.php)?  
id=23ijo23jnjknbdc&uid=32lknklfelkj32

user =\> controller  
jump =\> action  
[http://www.myvendor.com/referral.php](http://www.myvendor.com/referral.php)?  
id=23ijo23jnjknbdc&uid=32lknklfelkj32 =\> string/parameter

I don’t know it’s possible to do this because the url itself contains  
‘/’. Any ideas?

---

<div class="post-metadata">

**Author:** ![aantix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f0a364/32.png) [@aantix](https://www.ruby-forum.com/u/aantix)\
**Post date:** [December 14, 2005, 9:45pm UTC](https://www.ruby-forum.com/t/advanced-routing-question/50284/2 "2005-12-14T21:45:52Z")

</div>

Jim J. wrote:

> Hello All,
> 
> I’m making a quick application that tracks outgoing links to referral  
> sites. I need to track the user and the url they went to so the  
> easiest way would be to take the entire url as a parameter and log  
> that into the database. I was wondering if I could do something like  
> this with routing:
> 
> [http://www.example.com/user/jump/http://www.myvendor.com/referral.php](http://www.example.com/user/jump/http://www.myvendor.com/referral.php)?  
> id=23ijo23jnjknbdc&uid=32lknklfelkj32
> 
> user =\> controller  
> jump =\> action  
> [http://www.myvendor.com/referral.php](http://www.myvendor.com/referral.php)?  
> id=23ijo23jnjknbdc&uid=32lknklfelkj32 =\> string/parameter
> 
> I don’t know it’s possible to do this because the url itself contains  
> ‘/’. Any ideas?

You should be able to use the ‘generic URL’ form of routing:

map.connect ‘user/jump/\*path’, # …

This way, params[:path] will have the path information.

You will almost certainly want to URI.encode(url\_string)  
when generating the links and it might not be a bad idea  
to Base64-encode it as well, just to avoid any problems:

require ‘base64’

url = Base64.decode64(Base64.encode64(url))

E

---

<div class="post-metadata">

**Author:** ![aantix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f0a364/32.png) [@aantix](https://www.ruby-forum.com/u/aantix)\
**Post date:** [December 15, 2005, 3:55am UTC](https://www.ruby-forum.com/t/advanced-routing-question/50284/3 "2005-12-15T03:55:05Z")

</div>

Thanks a lot Eero!

* * *

Jim J.  
“A trustworthy individual.”  
[www.DontTrustThisGuy.com](http://www.DontTrustThisGuy.com)  
(480) 235-5201

---

<div class="post-metadata">

**Author:** ![aantix](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f0a364/32.png) [@aantix](https://www.ruby-forum.com/u/aantix)\
**Post date:** [January 9, 2006, 8:30am UTC](https://www.ruby-forum.com/t/advanced-routing-question/50284/4 "2006-01-09T08:30:32Z")

</div>

Hey guys,

I want to create a program that automatically edits alll links on a  
template to pass through a redirect action so that I can track a  
users click through in a centralized affiliate program. The problem  
I’m running into is that I basically am appending the entire url to  
the end of the redirect url so I want rails routing to ignore the  
path and leave it intact. So I tried out the following routing scenario:  
map.connect ‘jump/:id/\*path’, :controller =\> ‘jump’, :action =\>  
‘send\_to’

To handle redirects such as:  
[http://localhost:3000/jump/JIM/http://click.linksynergy.com/fs-bin/](http://localhost:3000/jump/JIM/http://click.linksynergy.com/fs-bin/)  
click?id=a7YZwGZeWSw&offerid=95247.10000349&type=4&subid=0&u1=JIM

But what ends up happening is I get path returned as an array that  
was separated by ‘/’ and each of the items in the query string are  
broken into individual params. Any one have any idea how to avoid  
this? Or is there a better way?

- Jim
