user7010020
user7010020

Reputation:

Couldn't find Item with 'id'=; Destroy action

I needed to customize my controllers so I did this:

routes:

post    'add_item', to: 'walls#create'
delete  'remove_item', to: 'walls#destroy'

destroy action WallsController:

def destroy
  @item = Item.find params[:id]
  @item.destroy
  redirect_to :back
end

view:

<% @items.each do |item| %>
  <%= item.name %> <%= link_to "X", remove_item_path(item), method: :delete %>
<% end %>

Create action works just fine but still getting error with destroy action: Couldn't find Item with 'id'=

Many thanks for help

Upvotes: 0

Views: 748

Answers (2)

user7010020
user7010020

Reputation:

This works:

link_to "X", remove_item_path(id: item.id), method: :delete

Upvotes: 0

fedebns
fedebns

Reputation: 494

remove_item_path is expecting an item id as argument.

link_to "X", remove_item_path(item.id), method: :delete

Upvotes: 1

Related Questions