目标是移除一个物品;我得到的印象的错误是在我的路线:没有路线匹配[DELETE]“/”;红宝石在轨道上
Rails.application.routes.draw do
devise_for :users
resources :users, only: [:show, :destroy]
resources :items, only: [:new, :index, :create, :destroy]
resources :welcome, only: [:index]
get 'items/new'
root 'items#index'
end
的部分如下:
<p><%= item.name %></p>
<%= link_to "Done!", root_path, method: :delete, class: 'glyphicon glyphicon-ok' %>
和公正的情况下,以下是我items_controller销毁行动:
def destroy
@item = Item.find(params[:id])
if @item.destroy
flash[:notice] = "You accomplished a task!"
redirect_to root_path
else
flash.now[:alert] = "There was an error deleting the task. Try again."
end
end
如前所述,我觉得这是我的路线,尽管我一直在修补他们。有人看到我误解了什么吗?
谢谢。
你需要知道你所删除的特定项目的项目路径。所以item_path('@ item')我想? – karina
这样做,谢谢! – sergio
我会给@Hamms的答案他是更完整的答案...也许我应该停止尝试从我的手机回答问题... – karina