url = Addressable::URI.parse("https://my.url?with=a&lot=of¶meters")
How do I get the base url without ANY query parameter, without knowing which parameters or how many there are?
I can't do url.query_values = {}
because I also need the original url at some point.
CodePudding user response:
What you want is to use omit
:
Addressable::URI#omit(*components) ⇒ Addressable::URI
Omits components from a 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"
If you also don't want the hash or other components, pass them to omit
as well:
url.omit(:query, :hash)