url = Addressable::URI.parse("https://my.url?with=a&lot=of¶meters")
如何在不知道哪些引數或有多少引數的情況下獲取沒有任何查詢引數的基本 url?
我不能這樣做url.query_values = {},因為我有時也需要原始網址。
uj5u.com熱心網友回復:
你想要的是使用omit:
Addressable::URI#omit(*components) ? Addressable::URI省略 URI 中的組件。
url = Addressable::URI.parse('https://sub.example.com/path/to/foo?x=1&y=2#hash')
url.omit(:query).to_s
# =>
"https://sub.example.com/path/to/foo#hash"
如果您也不想要哈希或其他組件,請將它們omit也傳遞給:
url.omit(:query, :hash)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/445015.html
標籤:红宝石
