# How to encode spaces in get params

**URL:** <https://www.ruby-forum.com/t/how-to-encode-spaces-in-get-params/132792>\
**Category:** Rails\
**Created:** [March 24, 2008, 7:42pm UTC](https://www.ruby-forum.com/t/how-to-encode-spaces-in-get-params/132792 "2008-03-24T19:42:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [March 24, 2008, 7:42pm UTC](https://www.ruby-forum.com/t/how-to-encode-spaces-in-get-params/132792/1 "2008-03-24T19:42:23Z")

</div>

Hi-

Easy question, just don’t know where to look-

How do I encode an :id that has a space in it:

#tag.tag = “Joe B.”

\<% = link\_to tag.tag, {:action =\> stories\_by\_tag, :id =\> tag.tag} %\>

this throws an error b/c there is a space in the id. Is there a  
function that automatically encodes this? The h function doesn’t do  
it.

Thanks,  
Dino

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [March 25, 2008, 7:45am UTC](https://www.ruby-forum.com/t/how-to-encode-spaces-in-get-params/132792/2 "2008-03-25T07:45:23Z")

</div>

> \<% = link\_to tag.tag, {:action =\> stories\_by\_tag, :id =\> tag.tag} %\>
> 
> this throws an error b/c there is a space in the id. Is there a  
> function that automatically encodes this? The h function doesn’t do  
> it.
> 
> Thanks,  
> Dino

tag.tag.gsub(’ ', ‘%20’) ???
