该寻址创业板将这些归为你:
require 'addressable/uri' # normalize relative paths uri = Addressable::URI.parse('http://example.com/foo/bar/../jim/jam') puts uri.normalize.to_s #=> "http://example.com/foo/jim/jam" # removes trailing ? uri = Addressable::URI.parse('http://example.com/foo/jim/jam?') puts uri.normalize.to_s #=> "http://example.com/foo/jim/jam" # leaves empty parameters alone uri = Addressable::URI.parse('http://example.com/foo/jim/jam?jim') puts uri.normalize.to_s #=> "http://example.com/foo/jim/jam?jim" # remove specific query parameters uri = Addressable::URI.parse('http://example.com/foo/jim/jam?autho=&file=jam') cleaned_query = uri.query_values cleaned_query.delete('autho') cleaned_query.delete('file') uri.query_values = cleaned_query uri.normalize.to_s #=> "http://example.com/foo/jim/jam"