How do I safely join relative url segments?

前端 未结 11 1914
南方客
南方客 2020-12-30 19:27

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::         


        
11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 20:24

    Have uri as URI::Generic or subclass of thereof

    uri.path += '/123' 
    

    Enjoy!

    06/25/2016 UPDATE for skeptical folk

    require 'uri'
    uri = URI('http://ioffe.net/boris')
    uri.path += '/123'
    p uri
    

    Outputs

     
    

    Run me

提交回复
热议问题