Rails 2.0 RESTful Routes action/id dichotomy

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.

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.

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.

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://weblog.techno-weenie.net
http://mephistoblog.com

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 [email protected] wrote:

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


Posted via http://www.ruby-forum.com/.

Trevor S.
http://somethinglearned.com

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…

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

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.