softwareengineer 99
2006-Feb-14 09:14 UTC
[Rails] routes question [Catching URL in a variable]
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 --------------------------------- Yahoo! Mail Use Photomail to share photos without annoying attachments. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060214/f5a46f62/attachment.html
Alan Francis
2006-Feb-14 11:55 UTC
[Rails] Re: routes question [Catching URL in a variable]
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-- Posted via http://www.ruby-forum.com/.
Alan Francis
2006-Feb-14 11:58 UTC
[Rails] Re: routes question [Catching URL in a variable]
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.-- Posted via http://www.ruby-forum.com/.
Ezra Zygmuntowicz
2006-Feb-14 16:09 UTC
[Rails] Re: routes question [Catching URL in a variable]
On Feb 14, 2006, at 3:58 AM, Alan Francis wrote:> 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. >>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
softwareengineer 99
2006-Feb-14 20:49 UTC
[Rails] Re: routes question [Catching URL in a variable]
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:> 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-- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails --------------------------------- Yahoo! Mail Use Photomail to share photos without annoying attachments. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060214/fccec270/attachment.html
Jason Perkins
2006-Feb-14 20:59 UTC
[Rails] Re: routes question [Catching URL in a variable]
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.comI 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