This project is archived and is in readonly mode.
Unexpected behaviour in resource mapping
-
cousine
After playing around a little, i found that the ambiguity is not caused by resources
for example
map.resources :posts, :except => [:show]will correctly generate routes (in plural form) as expected
but if the following routes are drawn
map.resources :posts, :except => [:show] map.post "post/:id", :controller => 'posts', :action => 'show', :conditions => [:method => :get]Polymorphic routes would try to draw a route for delete based on the named route post, thus it generates "post/:id" for destroy while destroy is mapped with "posts/:id"
So far as the overriding route is sticking to the plural convention as the Resources route, no problem occurs, but its only irritating if the overriding route is different
for example this would work fine:
map.resources :posts, :except => [:show] map.post "posts/:id", :controller => 'posts', :action => 'show', :conditions => [:method => :get]but in this case:
map.resources :posts, :except => [:show] map.post "blog/:id", :controller => 'posts', :action => 'show', :conditions => [:method => :get]polymorphic_routes would generate a "blog/:id" for the destroy action, while its correct route is "posts/:id", to further show the irritation behind this, i found a solution which involves changing the resources statement to this:
map.resources :posts, :except => [:show], :as => "blog" map.post "blog/:id", :controller => 'posts', :action => 'show', :conditions => [:method => :get]this will solve the problem, but will change the entire route group to blog instead of posts, and "blog/new" is not equal in meaning as "posts/new".
-
Ryan Bigg
- State changed from new to wontfix
By defining
map.postyou are overridingpost_path/post_url, which is why you were seeing it going to the "wrong" route. Closing.