I've been converting my Rails 2.3.9 application to Rails 3.0 and everything has been going well. I've created a lot of routes with the new system so I feel like I know how to do this. However, I recently got a routing error I can't solve.
I have a users resource defined like this:
resources :users do
member do
get 'activate'
get 'edit_password'
post 'update_password'
end
collection do
get 'forgot_password'
post 'send_reset_instructions'
end
end
The failing route is update_password. If I change it to a get method it works. But not when used as a post, with data coming from a form in "edit_password".
This is the error message:
Routing Error
No route matches "/users/31/update_password"
This is the (relevant) output of rake routes:
activate_user GET /users/:id/activate(.:format) {:action=>"activate", :controller=>"users"}
edit_password_user GET /users/:id/edit_password(.:format) {:action=>"edit_password", :controller=>"users"}
update_password_user POST /users/:id/update_password(.:format) {:action=>"update_password", :controller=>"users"}
forgot_password_users GET /users/forgot_password(.:format) {:action=>"forgot_password", :controller=>"users"}
send_reset_instructions_users POST /users/send_reset_instructions(.:format) {:action=>"send_reset_instructions", :controller=>"users"}
users GET /users(.:format) {:action=>"index", :controller=>"users"}
users POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
user PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
user DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
Finally, this is the output of the web server for that request (webrick):
Started POST "/users/31/update_password" for 127.0.0.1 at 2010-10-14 23:30:59 +0200
SQL (1.5ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
SQL (0.7ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
ActionController::RoutingError (No route matches "/users/31/update_password"):
Rendered /home/jonatan/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.0/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)
Can you find any logic in this?
I'm using the latest Rails available through gem (3.0.1). At first I did override *to_param* in the User-model to use the username, but the problem is the same no matter what.
I've checked for misspellings in the update_password method of the model, and also made sure it is not private.