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


#1

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

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


#2

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

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.