hi. in order to better understand restful routes, i started with simple
routes and named routes. before doing map.resources :users in my app, i
decide to simulate all the 7 possibilities in my routes,rb file:
hi. in order to better understand restful routes, i started with
simple
routes and named routes. before doing map.resources :users in my
app, i
decide to simulate all the 7 possibilities in my routes,rb file:
I tested with user_path(user), but didn't solve the problem.
If I stack something like:
map.user ... (show)
map.user ... (update)
map.user ... (destroy)
Then the top first match should take place, which is the (show)
The reason I did that is because ... suppose I just have map.resources
users inside the routes.rb file and then I rake routes in the terminal
the result will be:
users GET /users {:action=>"index",
:controller=>"users"}
POST /users {:action=>"create",
:controller=>"users"}
new_user GET /users/new {:action=>"new",
:controller=>"users"}
edit_user GET /users/:id/edit {:action=>"edit",
:controller=>"users"}
user GET /users/:id {:action=>"show",
:controller=>"users"}
PUT /users/:id {:action=>"update",
:controller=>"users"}
DELETE /users/:id
{:action=>"destroy",:controller=>"users"}
And if you look at the last 3 paths you have user for GET, PUT and
DELETE, thats why I thought I should use just user instead of user_show,
user_update and user_delete and rails should know which one is the right
one by looking at the routes.rb and in the view. Well, appears that it
doesn't work that way, but why it does work with map.resources? I may be
missing something else?
why? because paths like that and also with simple paths, rails will be
reading and executing the routes.rb file with TOP_FIRST priority and
that's the rule!
in other words, the rake routes output, eg:
user GET /users/:id {:action=>"show",
:controller=>"users"}
PUT /users/:id {:action=>"update",
:controller=>"users"}
DELETE /users/:id {:action=>"destroy",
:controller=>"users"}
that output does NOT imply you can use same name paths and differentiate
then with different :methods!