Rails 3.0 Routing Error

I converted the Rails 2.3.9 application to Rails 3.0 and everything went well. I created many routes with the new system, so I feel that I know how to do this. However, I recently received a routing error that I cannot solve.

I have a user resource defined as follows:

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 failed route is update_password. If I change it to get method, it will work. But not when used as a message with data coming from the form in "edit_password".

This error message is:

 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 web server output for this 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 use the latest Rails available through gem (3.0.1). First I redefined * to_param * in the user model to use the username, but the problem is the same no matter what.

I checked the errors in the update_password method of the model and also made sure that it is not private.

+4
source share
1 answer

I also noticed this, only with the POST method and only when using "member", just like your example, i.e.

 resources :forum_posts do member do post :preview end end 

will cause this, but changing it to GET or using the collection, both work fine, so this seems to be an error with rail routes; I will get around this by adding the following just above my resources: forum_posts do line:

 match '/forum_posts/:id/preview(.:format)', :to => "forum_posts#preview", :as => :preview_forum_post 

then everything continues to work; easy interim fix.

+2
source

All Articles