title: Rails Deleting model object via AJAX
body: <p>I'm trying to remotely destroy an object using Ajax. This is what I've done:</p>
  
  <p>This is the destroy action in ProductsController</p>
  
  <pre><code>  def destroy
      @product = Product.find(params[:id])
      @product.destroy
      respond_to do |format|
        format.html {redirect_to products_path, success: 'Product destroyed successfully'}
        format.js {}
      end
    end
  </code></pre>
  
  <p>This is the destroy.js.erb inside products views</p>
  
  <pre><code>$(this).closest('tr').remove()
  </code></pre>
  
  <p>The interaction with the button is in a page with the following templates:
  Index template:</p>
  
  <pre><code>&lt;table class="table table-hover products"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Product&lt;/th&gt;
        &lt;th&gt;Stock&lt;/th&gt;
        &lt;th&gt;Cost&lt;/th&gt;
        &lt;th&gt;Price&lt;/th&gt;
        &lt;th&gt;Sell&lt;/th&gt;
        &lt;th&gt;Delete&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;%= render @products %&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;br/&gt;
  &lt;br/&gt;
  </code></pre>
  
  <p>This is _product template</p>
  
  <pre><code>&lt;tr&gt;
    &lt;td&gt;
      &lt;%= link_to product.title, edit_product_path(product) %&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;%= product.stock %&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;%= product.cost %&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;%= product.price %&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;%= button_to 'Sell Product', new_product_sale_path(product), method: :get, class: 'btn btn-secondary' %&gt;
    &lt;/td&gt;
    &lt;td&gt;
      &lt;%= button_to "Delete Product", product_path(product), remote: true, 
                                  method: :delete, data: { confirm: "Are you sure?" }, class: "btn btn-secondary" %&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>The destroy works, but the html is not updated accordingly. What am I missing ? Thanks</p>