我一直收到这些错误,因为没有路线匹配动作'编辑'
控制器:
def remove_artifact_from_collection
... do my stuff ..
render(:action=>:show)
end
查看:错误的行
<p><%= link_to 'Edit Evidence Item', edit_artifact_path, :class => 'edit_button' %></p>
路线:
resources :artifacts do
collection do
get 'remove_artifact_from_collection'
end
end
捆绑exec rake路线
remove_artifact_from_collection_artifacts GET /artifacts/remove_artifact_from_collection(.:format) {:controller=>"artifacts", :action=>"remove_artifact_from_collection"}
artifacts GET /artifacts(.:format) {:controller=>"artifacts", :action=>"index"}
POST /artifacts(.:format) {:controller=>"artifacts", :action=>"create"}
new_artifact GET /artifacts/new(.:format) {:controller=>"artifacts", :action=>"new"}
edit_artifact GET /artifacts/:id/edit(.:format) {:controller=>"artifacts", :action=>"edit"}
artifact GET /artifacts/:id(.:format) {:controller=>"artifacts", :action=>"show"}
PUT /artifacts/:id(.:format) {:controller=>"artifacts", :action=>"update"}
DELETE /artifacts/:id(.:format) {:controller=>"artifacts", :action=>"destroy"}
答案 0 :(得分:4)
那是因为您没有向edit_artifact_path
提供工件/ ID。假设您的工件位于@artifact
实例变量中,您应该使用:
link_to 'Edit Evidence Item', edit_artifact_path(@artifact), ...
你也可以使用:
link_to 'Edit Evidence Item', [:edit, @artifact], ...
答案 1 :(得分:1)
link_to "Edit Artifact", edit_artifact_path(@artifact)
你没有传入对象。
edit_artifact GET /artifacts/:id/edit(.:format)
从您可以看到的路径中,您需要指定ID。因此传入一个包含工件对象的变量。