我的路线文件中有以下内容:
resources :timelogs do
member do
post :stop
end
collection do
get :start
end
end
在'rake routes'上生成以下内容:
rake routes | grep stop
stop_timelog POST /timelogs/:id/stop(.:format) {:action=>"stop", :controller=>"timelogs"}
但是,当我向该网址发布请求时,我看到了:
Started POST "/timelogs/325/stop" for 188.220.17.64 at Wed Nov 24 02:22:22 -0800 2010
ActionController::RoutingError (No route matches "/timelogs/325/stop"):
所有这些看起来都应该有效,但事实并非如此。这可能是什么问题?
答案 0 :(得分:0)
我发现您粘贴的路线没有任何问题,并且已经确认它们是在临时应用中为我工作的。
Started POST "/timelogs/123/stop" for 127.0.0.1 at 2010-11-24 11:49:25 +0000
Processing by TimelogsController#stop as */*
Parameters: {"a"=>"b", "id"=>"123"}
Rendered text template (0.0ms)
Completed 200 OK in 60ms (Views: 59.9ms | ActiveRecord: 0.0ms)
你的routes.rb中的其他内容可能与此有冲突吗?
答案 1 :(得分:0)
实际上,当您尝试发送包含现有资源(票证)的表单时,默认情况下会发送PUT
请求,因此您应该设置:method => :post
清除或更改路由
post :resolve, :on => :member
到
put :resolve, :on => :member