# Url parameter :id with slash (/) failed to route

**URL:** <https://www.ruby-forum.com/t/url-parameter-id-with-slash-failed-to-route/62073>\
**Category:** Rails\
**Created:** [May 31, 2006, 8:46am UTC](https://www.ruby-forum.com/t/url-parameter-id-with-slash-failed-to-route/62073 "2006-05-31T08:46:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![figo2476](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@figo2476](https://www.ruby-forum.com/u/figo2476)\
**Post date:** [May 31, 2006, 8:46am UTC](https://www.ruby-forum.com/t/url-parameter-id-with-slash-failed-to-route/62073/1 "2006-05-31T08:46:22Z")

</div>

Hi there,

My routes.rb is something like

map.connect ‘:controller/:action/:id’

However, when a url request likes  
[http://xxx/user/category/a/b](http://xxx/user/category/a/b)

My intension is to call  
:controller =\> ‘user’  
:action =\> ‘category’  
:id =\> ‘a/b’

However, :id has slash in it (a/b) will make rails fail to route.  
(apache fail, webrick works fine somehow)

It seems like rails will try to match route rule with  
map.connect :controller/:action/:id/:others  
but failed.

I know one solution is to call CGI.escape in link\_to or url\_for , like  
link\_to :controller =\> ‘user’, :action =\> ‘category’, :id =\> CGI.escape  
(category)

and unescape when I got it.  
category = CGI.unescape(params[:category])

Any better solution ?  
Thanks.

Gary

---

<div class="post-metadata">

**Author:** ![figo2476](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/71e660/32.png) [@figo2476](https://www.ruby-forum.com/u/figo2476)\
**Post date:** [May 31, 2006, 8:51am UTC](https://www.ruby-forum.com/t/url-parameter-id-with-slash-failed-to-route/62073/2 "2006-05-31T08:51:56Z")

</div>

Gary L. wrote:

> Hi there,
> 
> My routes.rb is something like
> 
> map.connect ‘:controller/:action/:id’
> 
> However, when a url request likes  
> [http://xxx/user/category/a/b](http://xxx/user/category/a/b)
> 
> My intension is to call  
> :controller =\> ‘user’  
> :action =\> ‘category’  
> :id =\> ‘a/b’
> 
> However, :id has slash in it (a/b) will make rails fail to route.  
> (apache fail, webrick works fine somehow)  
> Thanks.
> 
> Gary

Rails routes really don’t like to do that. I would recommend coming up  
with a diiferent way to handle those id’s that doesn’t require a slash.
