# RESTful routing: allowing .s \[dots\] in ids

**URL:** <https://www.ruby-forum.com/t/restful-routing-allowing-s-dots-in-ids/155255>\
**Category:** Rails\
**Created:** [December 9, 2008, 9:42pm UTC](https://www.ruby-forum.com/t/restful-routing-allowing-s-dots-in-ids/155255 "2008-12-09T21:42:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [December 9, 2008, 9:42pm UTC](https://www.ruby-forum.com/t/restful-routing-allowing-s-dots-in-ids/155255/1 "2008-12-09T21:42:36Z")

</div>

Hi Folks,

I’m trying to set up a RESTful route in my rails app and have hit a  
snag. My application allows various different types of querying centered  
around a search phrase, and I decided it’d be nice to that in my RESTful  
API by exposing resources like:

> **[应用宝官网-全网最新最热手机应用游戏下载](https://sj.qq.com)**
>
> 应用宝是腾讯旗下官方手机app应用商店，致力于为您提供海量、优质、安全、最新的安卓应用游戏下载！

for basic information about the phrase, and then

> **[应用宝官网-全网最新最热手机应用游戏下载](https://sj.qq.com)**
>
> 应用宝是腾讯旗下官方手机app应用商店，致力于为您提供海量、优质、安全、最新的安卓应用游戏下载！

for a specific query on that phrase (it’s popularity in this case).

Essentially I’m trying to represent the search space as a resource  
space, with one resource for each possible phrase.

I set up the following in my routes.rb, and it ALMOST works:

map.resources(  
:keyword\_research,  
:controller =\> ‘api/v3/keyword\_research’ ,  
:member =\> {:index =\> :get, :popularity =\> :get }  
)

I can then use something like the following to generate resource URLs:  
keyword\_research\_url( ‘some search phrase’ )  
and  
popularity\_keyword\_research\_url( ‘some search phrase’ )

The only problem is when the search phrase contains a dot. That leads to  
urls like:

> **[应用宝官网-全网最新最热手机应用游戏下载](https://sj.qq.com)**
>
> 应用宝是腾讯旗下官方手机app应用商店，致力于为您提供海量、优质、安全、最新的安卓应用游戏下载！

and

> **[应用宝官网-全网最新最热手机应用游戏下载](https://sj.qq.com)**
>
> 应用宝是腾讯旗下官方手机app应用商店，致力于为您提供海量、优质、安全、最新的安卓应用游戏下载！

which confuses the routing system to no end. This results in various  
errors such as template missing, no route found, etc etc. Essentially I  
think the routing system is interpretting the dotted id as specifying a  
representation type, or something similar.

I thought a nice solution would be to encode the search\_phrase portion  
of these resource urls when I generate them, leading to urls like:

> **[应用宝官网-全网最新最热手机应用游戏下载](https://sj.qq.com)**
>
> 应用宝是腾讯旗下官方手机app应用商店，致力于为您提供海量、优质、安全、最新的安卓应用游戏下载！

and

> **[应用宝官网-全网最新最热手机应用游戏下载](https://sj.qq.com)**
>
> 应用宝是腾讯旗下官方手机app应用商店，致力于为您提供海量、优质、安全、最新的安卓应用游戏下载！

I’ve tested urls encoded like this and they appear to play nicely with  
the routing I have, and are within the specs AFAIK. I’d be happy with  
this, but the problem is that I don’t know how to generate urls like  
this using the url helper methods.

Anyone have any ideas? I’d be open to either a clean way to support  
un-encoded dots, or some advice on how to get ids with the dots encoded  
out of the url helpers. Or some other elegant solution, of course!

Thanks,  
Pete

---

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [December 9, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/restful-routing-allowing-s-dots-in-ids/155255/2 "2008-12-09T23:45:31Z")

</div>

See [http://dev.rubyonrails.org/ticket/6426](http://dev.rubyonrails.org/ticket/6426).

One solution is to add  
module ActionController::Routing  
SEPARATORS = %w( / ; , ? )  
end  
in your controller. I’m not sure if this still works under recent  
versions of Rails.

Lee

On Dec 9, 3:42 pm, Pete H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [December 10, 2008, 1:09am UTC](https://www.ruby-forum.com/t/restful-routing-allowing-s-dots-in-ids/155255/3 "2008-12-10T01:09:13Z")

</div>

I haven’t tried it with a restful route, but I have a route like this:

```
 r.curriculum '/curriculum/:code/:title/:action',
              :defaults => { :action => 'overview' },
              :requirements => { :code => %r([\d.]+) }

```

:code is a float-like number. 11.123, etc. The above :requirements  
part let’s digits/dots through. Before I added that my memory is it  
complained like you say.

Perhaps you can work that into the restful route somehow…

---

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [December 10, 2008, 5:16am UTC](https://www.ruby-forum.com/t/restful-routing-allowing-s-dots-in-ids/155255/4 "2008-12-10T05:16:24Z")

</div>

Lee F. wrote:

> See [http://dev.rubyonrails.org/ticket/6426](http://dev.rubyonrails.org/ticket/6426).
> 
> One solution is to add  
> module ActionController::Routing  
> SEPARATORS = %w( / ; , ? )  
> end  
> in your controller. I’m not sure if this still works under recent  
> versions of Rails.
> 
> Lee
> 
> On Dec 9, 3:42ï¿½pm, Pete H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks Lee, but like Philip’s solution this also doesn’t allow API  
clients to specify a format by appending a .xml (or .html or .csv or  
whatever).

---

<div class="post-metadata">

**Author:** ![moredip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@moredip](https://www.ruby-forum.com/u/moredip)\
**Post date:** [December 10, 2008, 5:14am UTC](https://www.ruby-forum.com/t/restful-routing-allowing-s-dots-in-ids/155255/5 "2008-12-10T05:14:46Z")

</div>

Philip H. wrote:

> I haven’t tried it with a restful route, but I have a route like this:
> 
> ```
> r.curriculum '/curriculum/:code/:title/:action',
> :defaults => { :action => 'overview' },
> :requirements => { :code => %r([\d.]+) }
> 
> ```
> 
> :code is a float-like number. 11.123, etc. The above :requirements  
> part let’s digits/dots through. Before I added that my memory is it  
> complained like you say.
> 
> Perhaps you can work that into the restful route somehow…

Thanks Philip, I tried this tack but it doesn’t work with a url where  
the id is at the end. If we have a path like:

/curriculum/12.1

the routing can’t distinguish between id 12 with a format of 1 and an id  
of 12.1. This is compounded by the fact that my API clients need to be  
able to tack .xml on to the end of urls when they need an xml  
representation.

☹
