Forum: Ruby on Rails routes question [Catching URL in a variable]

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F68e4842b0a5487678e26046fdb2fdf3?d=identicon&s=25 softwareengineer 99 (Guest)
on 2006-02-14 10:14
(Received via mailing list)
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
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-02-14 12:55
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
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-02-14 12:58
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 Francis wrote:
> Possibly unrelated, but that URLs probably not legal.   The secondary
> url needs to be encoded.
>
> A.
8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-14 17:13
(Received via mailing list)
On Feb 14, 2006, at 3:58 AM, Alan Francis 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 Zygmuntowicz
WebMaster
Yakima Herald-Republic Newspaper
ezra@yakima-herald.com
509-577-7732
F68e4842b0a5487678e26046fdb2fdf3?d=identicon&s=25 softwareengineer 99 (Guest)
on 2006-02-14 21:50
(Received via mailing list)
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 Francis <alancfrancis@gmail.com> 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/.
2899cec9af525f7953e19c8210aca97c?d=identicon&s=25 Jason Perkins (Guest)
on 2006-02-14 21:59
(Received via mailing list)
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 Perkins
2899cec9af525f7953e19c8210aca97c?d=identicon&s=25 Jason Perkins (Guest)
on 2006-02-14 22:02
(Received via mailing list)
On Feb 14, 2006, at 2:59 PM, Jason Perkins wrote:

> I think he meant, "check the 1738,

Should read, "check the RFC"

--
Jason Perkins
This topic is locked and can not be replied to.