small medium large xlarge

19 Jan 2016, 00:29
Ryan Marshall (1 post)

Hello, I’ve recently completed what the title states, and my destroy link doesn’t work. When clicked, it just takes me to the table data its self, listing out title, description, image url, and, price.

I have done some digging around and can’t seem to find a duplicate of this issue. It may be worth noting that I do not have a file called “Destroy” to link to, though I do have the files show and edit.

my code can be found below. Any help is appreciated.

<h1>Listing products</h1>

  <% @products.each do |product| %>
  <tr class="<%= cycle('list_line_odd, list_line_even') %>">
      <%= image_tag(product.image_url, class: 'list_image') %>      

    <td class="list_description">
        <dt><%= product.title %></dt>
        <dd><%= truncate(strip_tags(product.description),
        length:80) %></dd>

    <td class="list_actions">
      <%= link_to 'Show', product %><br/>
      <%= link_to 'Edit', edit_product_path(product) %><br/>
      <%= link_to 'Destroy', product,
      confirm: 'Are you sure?',
      method: :delete %>
  <% end %>


<br />

<%= link_to 'New Product', new_product_path %>
19 Jan 2016, 03:36
Sam Ruby (633 posts)

I’ll start by saying that I don’t see anything wrong with the code you posted. But first a comment:

It may be worth noting that I do not have a file called “Destroy” to link to

That’s not how this works. The text in quotes is just the text that shows up on the web page. You can change that to whatever you want without changing the function.

The important parts come next: product and method: :delete. This is what is sent to the server to be processed by app/controllers/products_controller.rb. In particular, it is processed by the method named destroy. Please double check that method for errors. Feel free to post what you have there.

You must be logged in to comment