Routes question [Catching URL in a variable]


#1

Hello Rails Gurus,

I have spent the entire night trying to figure this out with no luck.
I will really appreciate if someone can come to my rescue.

I have a URL like the following:

http://domain.com/resource/http://www.rubyonrails.org

and would like to capture the rubyonrails URL after the
http://domain.com/resource/ part in a variable.

I tried something like

map.connect ‘resource/:protocol//:link’ …

but since I cannot accurately predict the number of forward slashes
involved, I cannot hard code the route.

Is there any way I can tell in routes.rb to capture everything after
“resource/” part and store it in a variable?

I highly appreciate your assistance.

Frank


#2

Possibly unrelated, but that URLs probably not legal. The secondary
url needs to be encoded.

A.

softwareengineer 99 wrote:

Hello Rails Gurus,

I have spent the entire night trying to figure this out with no luck.
I will really appreciate if someone can come to my rescue.

I have a URL like the following:

http://domain.com/resource/http://www.rubyonrails.org

and would like to capture the rubyonrails URL after the
http://domain.com/resource/ part in a variable.

I tried something like

map.connect ‘resource/:protocol//:link’ …

but since I cannot accurately predict the number of forward slashes
involved, I cannot hard code the route.

Is there any way I can tell in routes.rb to capture everything after
“resource/” part and store it in a variable?

I highly appreciate your assistance.

Frank


#3

Oops, early send.

http://domain.com/resource/http%3A%2F%2Fwww.rubyonrails.org

It could be that by escaping the reserved characters, your life gets a
bit easier in the routing.

A.

Alan F. wrote:

Possibly unrelated, but that URLs probably not legal. The secondary
url needs to be encoded.

A.


#4

On Feb 14, 2006, at 3:58 AM, Alan F. wrote:

Possibly unrelated, but that URLs probably not legal. The secondary
url needs to be encoded.

Frank-

You can also just use a catch all route to handle this:

map.connect ‘/resource/*url’, :controller => ‘foo’, :action => ‘bar’

Make sure to put that route at the bottom of your routes file so it

doesn’t match other urls on accident.

Cheers-
-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
removed_email_address@domain.invalid
509-577-7732


#5

Thanks for the reply. The URL is legal, see:
http://technorati.com/search/http://www.google.com

The funny thing is when I encode the URL, Apache doesn’t pass the
request to dispatcher.fcgi. For unencoded URLs the request gets passed
perfectly and the only issue is how to determine the number of slashed
(nearly impossible).

So it means we cannot tell Rails via routes.rb that to catch
everything after a certain string in a variable, unles its encoded.

Thank you very much for your replies.

Frank

Alan F. removed_email_address@domain.invalid wrote: Possibly unrelated, but
that URLs probably not legal. The secondary
url needs to be encoded.

A.

softwareengineer 99 wrote:

http://domain.com/resource/ part in a variable.

I highly appreciate your assistance.

Frank


Posted via http://www.ruby-forum.com/.


#6

On Feb 14, 2006, at 2:59 PM, Jason P. wrote:

I think he meant, "check the 1738,

Should read, “check the RFC”


Jason P.


#7

On Feb 14, 2006, at 2:49 PM, softwareengineer 99 wrote:

Thanks for the reply. The URL is legal, see:
http://technorati.com/search/http://www.google.com

I think he meant, “check the 1738,” instead of, “see if, as an edge
case, you can get this to work on any websites.” And RFC 1738 reads:

Many URL schemes reserve certain characters for a special meaning:
their appearance in the scheme-specific part of the URL has a
designated semantics. If the character corresponding to an octet is
reserved in a scheme, the octet must be encoded.  The characters

“;”,
“/”, “?”, “:”, “@”, “=” and “&” are the characters which may be
reserved for special meaning within a scheme. No other characters
may
be reserved within a scheme.

Usually a URL has the same interpretation when an octet is
represented by a character and when it encoded. However, this is not
true for reserved characters: encoding a character reserved for a
particular scheme may change the semantics of a URL.

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL.

On the other hand, characters that are not required to be encoded
(including alphanumerics) may be encoded within the scheme-specific
part of a URL, as long as they are not being used for a reserved
purpose.

The third paragraph is relevant to what you’re suggesting.


Jason P.