library for URL parameters adding, removing, or replacing?

i think PHP doesn't have such simple functions yet... does Ruby have it?

if in PHP, when we add a param to the URL

$redirectURL = $printPageURL . "?mode=1";

it works if $printPageURL is "", but if $printPageURL is changed in the global file to "", then the URL becomes badly formed. If the project has 300 files and there are 30 files that append param this way, we need to change all 30 files.

the same if we append using "&mode=1" and $printPageURL changes from "" to "", then the URL is also badly formed.

is there a library in Ruby/Rails that will automatically handle the "?" and "&", and even checks that existing param exists already and removed that one because it will be replaced by the later one and it is not good if the URL keeps on growing longer?

URL paramaters are usually passed as a hash, with that if a new key matches and existing key the new key/value pair will overwrite the existing key/value pair thus preventing duplicate entries.