Forum: Ruby how to get an absolute address of a link

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.
Ce521842cff87983fa0ab297b1d9317b?d=identicon&s=25 Tsunami Scripter (tsunami)
on 2009-01-28 12:32
Is there some URL lib that I can use to get the absolute address of a
relative URL ? Maybe I could pass a "base" link to the method . Ideally
, I would like to know if this could by achieved from mechanize , but
anything would do .
I wrote my own a while back , and I'm using it , but I would like to
know if something already exists .
7e593ac63e5f25649b701dc25f69d1b7?d=identicon&s=25 Luis Parravicini (Guest)
on 2009-01-28 17:28
(Received via mailing list)
On Wed, Jan 28, 2009 at 9:30 AM, Tsunami Script <lyon2003@lycos.com>
wrote:
> Is there some URL lib that I can use to get the absolute address of a
> relative URL ? Maybe I could pass a "base" link to the method . Ideally
> , I would like to know if this could by achieved from mechanize , but
> anything would do .

You can use URI.join

 irb -ruri
irb(main):001:0> URI.join('http://example.com', '/path/a/b')
=> #<URI::HTTP:0xb7ce2b08 URL:http://example.com/path/a/b>
irb(main):002:0> URI.join('http://example.com',
'http://google.com/path/a/b')
=> #<URI::HTTP:0xb7cdf28c URL:http://google.com/path/a/b>
irb(main):003:0>
Ce521842cff87983fa0ab297b1d9317b?d=identicon&s=25 Tsunami Scripter (tsunami)
on 2009-01-28 17:35
Very nice ! Thanks ! I was wondering if it would handle joins with
arguments like

arg1 = "http://site.com"
arg2 = "index.html"

or arg1 = "http://site.com/"
   arg2 = "/index.html"

and it seems to work great . Thank you !
This topic is locked and can not be replied to.