Routes.rb priorities and REST resources; Bug or documentatio

I came across this little annoyance(?!) while upgrading a project
from 1.1.6 to Edge Rails.

I was trying to add a resource mapping for my Post model.

I did as instructed and added…

map.resources :posts

…to config/routes.rb. What I didn’t pay much attention to was that
I added the command to the very end of the file (before the ‘end’
keyword of course; I am not that thick!).

Anyway, everything seemed to work fine until I tried a CRUD operation
other than the ‘/posts’ index action. I started getting strange
‘Unknown Action 2’ messages.

Well, it took me a couple hours to figure it out; any mapped
resources must be added before these two lines in routes.rb:

# Install the default route as the lowest priority.
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'

I haven’t had a chance to investigate if this is a routing bug (the
code looks a tad scary!). Or maybe it is just a vague point in the
documentation (i.e. routes.rb comments)

I fear this little detail might get in the way of a lot of people who
are eager to jump into REST, and might not spend enough time to read
the comments, even if they are in front of them.

Before REST it might not have been an issue as simple apps never
touched routes.rb. Now though…

-christos

I haven’t had a chance to investigate if this is a routing bug (the
code looks a tad scary!). Or maybe it is just a vague point in the
documentation (i.e. routes.rb comments)

I fear this little detail might get in the way of a lot of people who
are eager to jump into REST, and might not spend enough time to read
the comments, even if they are in front of them.

Before REST it might not have been an issue as simple apps never
touched routes.rb. Now though…

Routes go from top to bottom. This has always been a key point with
routes.

I find myself actually removing the default open connect route and
only going with explicitly set routes/resources.


Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com

hi,

2006/10/26, Rick O. [email protected]:

I find myself actually removing the default open connect route and
only going with explicitly set routes/resources.

and this is much more important if you want to somehow limit your app
to what is offered as a restful resource since if you don’t remove the
default routes then the canonical actions will be available!

bye
Luca M.


http://spazidigitali.com - http://thetyper.com