0

我不断收到这些错误,因为“编辑”操作没有路线匹配

控制器:

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

bundle 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"}
4

2 回答 2

4

那是因为您没有向edit_artifact_path. 假设您的工件在@artifact实例变量中,您应该使用:

link_to 'Edit Evidence Item', edit_artifact_path(@artifact), ...

您还可以使用:

link_to 'Edit Evidence Item', [:edit, @artifact], ...

于 2012-10-24T17:24:36.723 回答
1
link_to "Edit Artifact", edit_artifact_path(@artifact)

你没有传入对象。

edit_artifact GET    /artifacts/:id/edit(.:format) 

从路径可以看出,需要指定id。所以传入一个包含工件对象的变量。

于 2012-10-24T17:37:50.720 回答