How do I safely join relative url segments?

117 viewsrubyuriruby uri
0

I’m trying to find a robust method of joining partial url path segments together. Is there a quick way to do this?

I tried the following:

puts URI::join('resource/', '/edit', '12?option=test')

I expect:

resource/edit/12?option=test

But I get the error:

`merge': both URI are relative (URI::BadURIError)

I have used File.join() in the past for this but something does not seem right about using the file library for urls.