class ActionController::Parameters

def to_query(*args)

are sorted lexicographically in ascending order.
The string pairs "key=value" that conform the query string

# => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
safe_params.to_query("user")
safe_params = params.permit(:name, :nationality)
})
nationality: "Danish"
name: "David",
params = ActionController::Parameters.new({

An optional namespace can be passed to enclose key names:

# => "name=David&nationality=Danish"
safe_params.to_query
safe_params = params.permit(:name, :nationality)

# => ActionController::UnfilteredParameters: unable to convert unpermitted parameters to hash
params.to_query
})
nationality: "Danish"
name: "David",
params = ActionController::Parameters.new({

query string:
Returns a string representation of the receiver suitable for use as a URL
def to_query(*args)
  to_h.to_query(*args)
end