I have a Rails 3 engine gem that is for basic user authentication and authorization. Within that Gem the config/routes.rb defines the following
resources :users
match '/:controller(/:action(/:id))'
When I do a rake routes from the application that requires this gem I get the following routes
rake routes|grep users
users GET /users(.:format) {:controller=>"users", :action=>"index"}
users POST /users(.:format) {:controller=>"users", :action=>"create"}
new_user GET /users/new(.:format) {:controller=>"users", :action=>"new"}
edit_user GET /users/:id/edit(.:format) {:controller=>"users", :action=>"edit"}
user GET /users/:id(.:format) {:controller=>"users", :action=>"show"}
user PUT /users/:id(.:format) {:controller=>"users", :action=>"update"}
user DELETE /users/:id(.:format) {:controller=>"users", :action=>"destroy"}
This is what I expect.
However when I try to access the following routes via a browser
/users/137
/users/137/edit
I get the following error in the logs
AbstractController::ActionNotFound (The action '137' could not be found for UsersController):
actionpack (3.0.0) lib/abstract_controller/base.rb:114:in `process'
actionpack (3.0.0) lib/abstract_controller/rendering.rb:40:in `process'
...
What is interesting is that the following paths do work
/users/show/137
/users/edit/137
Also if I add the following to the routes.rb file in the application that is requiring the gem it all works as expected.
resources :users
Is there something I am missing or is this a bug?
Note that I am also doing the following when I start my application
on the command line when I start the rails I set the following env variable
RAILS_RELATIVE_URL_ROOT="/my_app"
and in config.ru
map '/my_app' do
run MSEL::Application
end
I experienced the same thing with a gem that I was creating. The engine routes are loaded after the application routes and I think this may be your problem. Take a look at
rake routeswithout grepping for user. I suspect that you have a route in your application that takes precedence over the user routes. If you havematch '/:controller(/:action(/:id))'in your application routes, then this will take precedence over the gem user route. Might explain why /users/show/137 works and not the RESTful routes. It may be possible to load your routes in the engine initializer to take precedence over the application routes. Post your fullrake routesresults and that may help us find a solution.