0

the delete method is not working when trying to destroy a record. When clicking on the button, it will redirect me to shops#show action, looks like the method: :delete is not working...Any help please?

Routes

 resources :shops

HTML

<% @shops.sort.each do |shop| %>
    <tr>
      <td><%= shop.name %></td>
      <td><%= shop.email %></td>
      <td><%= shop.direction %></td>
      <td>
        <%= link_to '<button>Borrar</button>', shop, method: :delete, data: { confirm: "Seguro?" } %>
      </td>
    </tr>
  <% end %>

Controller

def destroy
    @shop = Shop.find(params[:id])
    @shop.destroy
    respond_to do |format|
      format.html { redirect_to "/sushiadmin", notice: 'Se ha editado la tienda.' }
      format.json { head :no_content }
    end
  end
Gibson
  • 2,055
  • 2
  • 23
  • 48

2 Answers2

0

Do this:

<%= link_to 'Borrar', shop, method: :delete, data: { confirm: "Seguro?" }, class: 'btn btn-primary' %>

And delete Shop.find

def destroy
    @shop.destroy
    respond_to do |format|
      format.html { redirect_to "/sushiadmin", notice: 'Se ha editado la tienda.' }
      format.json { head :no_content }
    end
end
luissimo
  • 916
  • 2
  • 10
  • 31
0

Try with this (specifying the url)

link_to  '<button>Borrar</button>' , shop_path( shop ), :method => 'delete', data: { confirm: "Seguro?" }

Acording with http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to

link_to(body, url, html_options = {})
inye
  • 1,786
  • 1
  • 23
  • 31