# Library for URL parameters adding, removing, or replacing?

**URL:** <https://www.ruby-forum.com/t/library-for-url-parameters-adding-removing-or-replacing/168862>\
**Category:** Rails\
**Created:** [May 26, 2009, 8:47pm UTC](https://www.ruby-forum.com/t/library-for-url-parameters-adding-removing-or-replacing/168862 "2009-05-26T20:47:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [May 26, 2009, 8:47pm UTC](https://www.ruby-forum.com/t/library-for-url-parameters-adding-removing-or-replacing/168862/1 "2009-05-26T20:47:12Z")

</div>

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 “[http://www.somesite.com/print.php](http://www.somesite.com/print.php)”, but if  
$printPageURL is changed in the global file to  
“[http://www.somesite.com/print.php?newUser=1](http://www.somesite.com/print.php?newUser=1)”, 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  
“[http://www.somesite.com/print.php?new=1](http://www.somesite.com/print.php?new=1)” to  
“[http://www.somesite.com/print.php](http://www.somesite.com/print.php)”, 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?

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [May 26, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/library-for-url-parameters-adding-removing-or-replacing/168862/2 "2009-05-26T22:45:29Z")

</div>

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.

Ben

On May 26, 11:47 am, Jian L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
