Forum: Ruby on Rails url parameter :id with slash (/) failed to route

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
29eef961fdac1ecacd2fb9a56dba41e3?d=identicon&s=25 Gary Lin (Guest)
on 2006-05-31 08:46
(Received via mailing list)
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
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-05-31 08:51
Gary Lin 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.
This topic is locked and can not be replied to.