Relative To Absolute Path Convertor

Is there a built in function/plugin that converts
relative paths from a html page to absolute ones?

Example:
target url: http://mysite.com/folder/url.html

url content:

some link

converted content:

< a href=“http://mysite.com/folder/link.html”>some link</ a>

How can I accomplish this using ruby ?

Dear Ciocan,

you could use something like

str=“http://mysite.com/folder/url.html
p File.dirname(str)
p File.basename(str)
p File.basename(str,".html")

Best regards,

Axel

On 6/19/07, ciocan [email protected] wrote:

converted content:

< a href=“http://mysite.com/folder/link.html”>some link</ a>

How can I accomplish this using ruby ?

Use URI#merge:

require ‘uri’
=> true

base = URI.parse(“http://mysite.com/folder/url.html”)
=> #<URI::HTTP:0x4160a54 URL:http://mysite.com/folder/url.html>

base.merge("/script.js").to_s
=> “http://mysite.com/script.js

base.merge(“link.html”).to_s
=> “http://mysite.com/folder/link.html

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs