我一直在将Rails 2.3.9应用程序转换为Rails 3.0,并且一切都进行得很顺利。我用新系统创建了很多路线,所以我觉得我知道如何做到这一点。但是,最近我得到了一个我无法解决的路由错误。Rails 3.0中奇怪的路由错误
我有一个用户的资源是这样定义的:
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
的失败路线update_password。如果我将其更改为get方法,则可以使用。但是,当用作帖子时,数据来自“edit_password”中的表单。
这是错误消息:
Routing Error
No route matches "https://stackoverflow.com/users/31/update_password"
这是耙路由的(相关的)输出:
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"}
最后,这是web服务器的该请求的输出(webrick):
Started POST "https://stackoverflow.com/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 "https://stackoverflow.com/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)
你能找到任何逻辑我吗这个?
我正在使用通过gem(3.0.1)提供的最新Rails。起初,我在用户模型中重写了* to_param *来使用用户名,但是无论如何,问题都是一样的。
我检查了模型的update_password方法中的拼写错误,并且确保它不是私有的。
如果将其从update_password更改为foo(以及您的控制器方法以及视图名称),会发生什么情况? – Maxem 2010-10-14 21:47:34
我试图将其更改为“updatera_password”(几乎瑞典语;)),但这也没有帮助。我想也许update_password是某种类型的som关键字,但显然并非如此。 – Jonatan 2010-10-14 22:57:13