# Rails 2.0 RESTful Routes action/id dichotomy

**URL:** <https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915>\
**Category:** Rails\
**Created:** [May 23, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915 "2007-05-23T21:09:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [May 23, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915/1 "2007-05-23T21:09:01Z")

</div>

I don’t have edge rails installed, otherwise I would just test it  
out. But in Rails 2.0 they are doing away with the semi-colon for  
several reasons. I think this is great, but it brings an interesting  
issue to the forefront that’s actually bothered me in 1.2 as well…

How will Rails differentiate between an action on the collection and  
the id? For instance, if you have:

map.resources :listings, :collection =\> {:search =\> :get}

listings/1  
listings/search (in 1.2 t it would be listings;search)

Interestingly this problem existed before if you tried to mix default  
routing with RESTful routes which you might want to do for aesthetic  
or hackish reasons.

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [May 23, 2007, 9:47pm UTC](https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915/2 "2007-05-23T21:47:06Z")

</div>

It is my understanding that most are recommending removing the default  
routes when using RESTful Rails.

# Resources routes

map.resources :listings, :collection =\> {:search =\> :get}

# Install the default route as the lowest priority.

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

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

But other than that, the same precedence is used in following routes  
as before.

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [May 24, 2007, 12:11am UTC](https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915/3 "2007-05-24T00:11:45Z")

</div>

Well that makes sense for the current version, but the point is that  
this conflict exists entirely within RESTful routes as of Rails 2.0.  
They must have done something to work around it. LIke maybe change the  
default member get to use singular form (ie. listing/1 instead of  
listings/1). Anyone have any idea?

PS. WTF is up with Google G.? Dropped messages all over the place,  
weird error messages, etc. This thread was empty in Google G. so I  
had to come to ruby-forum.

Robert W. wrote:

> It is my understanding that most are recommending removing the default  
> routes when using RESTful Rails.
> 
> # Resources routes
> 
> map.resources :listings, :collection =\> {:search =\> :get}
> 
> # Install the default route as the lowest priority.
> 
> # map.connect ‘:controller/:action/:id.:format’
> 
> # map.connect ‘:controller/:action/:id’
> 
> But other than that, the same precedence is used in following routes  
> as before.

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [May 24, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915/4 "2007-05-24T18:33:40Z")

</div>

> Interestingly this problem existed before if you tried to mix default  
> routing with RESTful routes which you might want to do for aesthetic  
> or hackish reasons.

Put your restful routes above your default routes. I actually remove  
my default ones altogether.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [May 24, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915/5 "2007-05-24T18:11:36Z")

</div>

Hey,

sorry if I’ve misinterpreted what you’re saying - but you’re  
speculating about a problem that (again, if I understand you  
correctly) does not exist.

The resources code (see resources.rb) adds collection routes before  
member routes - which means collection routes will take precedence  
during recognition.

HTH,  
Trevor

On 5/23/07, Gabe Da silveira [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > But other than that, the same precedence is used in following routes  
> > as before.
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

## –

Trevor S.  
[http://somethinglearned.com](http://somethinglearned.com)

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [May 24, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915/6 "2007-05-24T19:38:11Z")

</div>

Right, that’s the scenario I was thinking of. But I guess as long as  
you make sure your URL slugs never conflict with an action you’ll be  
okay.

Jean-Etienne D. wrote:

> But still, if you use smart urls, you can never know if in  
> /people/whatever whatever is an action, or an ID…

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [May 24, 2007, 7:29pm UTC](https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915/7 "2007-05-24T19:29:13Z")

</div>

But still, if you use smart urls, you can never know if in  
/people/whatever whatever is an action, or an ID…

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [May 24, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/rails-2-0-restful-routes-action-id-dichotomy/104915/8 "2007-05-24T19:44:49Z")

</div>

> Right, that’s the scenario I was thinking of. But I guess as long as  
> you make sure your URL slugs never conflict with an action you’ll be  
> okay.
> 
> Jean-Etienne D. wrote:
> 
> > But still, if you use smart urls, you can never know if in  
> > /people/whatever whatever is an action, or an ID…

Custom actions are defined explicitly, so you do know. Anything that’s  
defined explicitly is not an id. Usually, ids are in another class  
entirely anyway. Like they’re purely integers or they follow a stand  
form of perhaps 1-my-title. So there’s not even any logical overlap.
