views:

120

answers:

1

Today I am observing a peculiar behavior in my rails app.

I have defined the following route in routes.rb

map.namespace :admin do |admin|
 admin.resources :users
end

and when I use rake:routes, I see the following routes as expected:

admin_users GET /admin/users {:action => 'index, :controller => 'admin/users'}
....
....

which are perfectly namespaced both in terms of path_prefixes as well as name_prefixes.

I have the UsersController under app/controllers (not under app/controllers/admin), but somehow rails is picking up the UsersController under app/controllers instead of app/controllers/admin, is this a recent change in rails, where it falls back for the controller, when it doesn't find one?

A: 

It might be getting picked up by the default routes included at the bottom of routes.rb.

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'

For your purposes, it sounds like removing these may be a good idea.

Dave Pirotte
@Dave: Thanks for the feedback. Actually I removed those default routes a while ago. Even then with the default routes in place, admin/users/:id is also being picked using UsersController instead of Admin::UsersController. I don't understand why rails is picking the wrong controller.
satynos