Rails, rendering after destroy
<p>I have a Cart/show.html erb with that renders a partial called carts_row.html.erb</p>

<pre><code>    &lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;

&lt;/br&gt;
&lt;/br&gt;

&lt;div class="cart-container"&gt;
  &lt;%=render 'carts_row'%&gt;
&lt;/div&gt;




&lt;/p&gt;
</code></pre>

<p>In carts_row it's a shopping cart layout with forms to update quantity and destroy/remove item from your shopping cart.</p>

<pre><code>    &lt;h1&gt;Shopping Cart&lt;/h1&gt;

&lt;div class="shopping-cart"&gt;
  &lt;div class="column-labels"&gt;
    &lt;label class="product-image"&gt;Image&lt;/label&gt;
    &lt;label class="product-details"&gt;Product&lt;/label&gt;
    &lt;label class="product-price"&gt;Price&lt;/label&gt;
    &lt;label class="product-quantity"&gt;Quantity&lt;/label&gt;

    &lt;!-- adding update column to labels --&gt;
    &lt;label class="product-update"&gt;Update&lt;/label&gt;
    &lt;label class="product-removal"&gt;Remove&lt;/label&gt;
    &lt;label class="product-line-price"&gt;Total&lt;/label&gt;
  &lt;/div&gt;

  &lt;%if @cart.cart_items.size == 0%&gt;
  &lt;div class="text-center"&gt;
    &lt;p&gt;Looks like you have nothing in your cart! &lt;%=link_to 'Add something to your cart', products_path%&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;%end%&gt;

  &lt;br /&gt;
  &lt;br /&gt;
  &lt;%if @cart_items != nil%&gt;
    &lt;%@cart_items.each do |item|%&gt;

    &lt;div class="product"&gt;
      &lt;div class="product-image"&gt;
        &lt;%=image_tag(item.product.picture)%&gt;
      &lt;/div&gt;
      &lt;div class="product-details"&gt;
        &lt;div class="product-title"&gt;&lt;%=item.product.name%&gt;&lt;/div&gt;
        &lt;p class="product-description"&gt;&lt;%=item.product.description%&gt;&lt;/p&gt;
      &lt;/div&gt;
      &lt;div class="product-price"&gt;&lt;%=number_to_currency(item.product.price)%&gt;&lt;/div&gt;

      &lt;%=form_for item, remote: true do |f|%&gt;
      &lt;div class="product-quantity"&gt;
        &lt;%=f.number_field :quantity, value: item.quantity, min: 1, max: 8%&gt;
        &lt;%=f.hidden_field :product_id, value: item.product.id%&gt;
        &lt;!-- &lt;input type="number" value="&lt;%=item.quantity%&gt;" min="1" max="8"&gt; --&gt;
      &lt;/div&gt;
      &lt;div class="product-update"&gt;
        &lt;%=f.submit 'Update', class: "update-product"%&gt;
        &lt;!-- &lt;%=f.hidden_field :product_id, value: item.product.id%&gt; --&gt;
        &lt;!-- &lt;button class="update-product"&gt;
          Update
        &lt;/button&gt; --&gt;
      &lt;/div&gt;
      &lt;div class="product-removal"&gt;
        &lt;%= link_to "Remove", item, {data: {confirm: "Are you sure you wish to delete the product '#{item.product.name}' from your cart?"}, method: :delete, remote: true, class: "remove-product"}%&gt;
        &lt;!-- &lt;button class="remove-product"&gt;
          Remove
        &lt;/button&gt; --&gt;
        &lt;%end%&gt;
      &lt;/div&gt;
      &lt;div class="product-line-price"&gt;&lt;%=number_to_currency(item.product.price*item.quantity)%&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;%end%&gt;
  &lt;%end%&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;!--Temporary solution until model methods are written  --&gt;
&lt;% if @cart_items != nil%&gt;
  &lt;!--subtotal variable --&gt;
  &lt;%subtotal =@cart_items.collect {|item| item.quantity*item.unit_price}.sum%&gt;
  &lt;!--subtotal + shipping cost  --&gt;
  &lt;%total=subtotal+15%&gt;
&lt;%end%&gt;
&lt;div class="totals"&gt;
  &lt;div class="totals-item"&gt;
    &lt;label&gt;Subtotal&lt;/label&gt;
    &lt;div class="totals-value" id="cart-subtotal"&gt;&lt;%=subtotal%&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="totals-item"&gt;
    &lt;label&gt;Tax (5%)&lt;/label&gt;
    &lt;div class="totals-value" id="cart-tax"&gt;Included!&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="totals-item"&gt;
    &lt;label&gt;Shipping&lt;/label&gt;
    &lt;div class="totals-value" id="cart-shipping"&gt;15.00&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="totals-item totals-item-total"&gt;
    &lt;label&gt;Grand Total&lt;/label&gt;
    &lt;div class="totals-value" id="cart-total"&gt;
      &lt;%=total%&gt;
    &lt;/div&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;div class="checkout-btn"&gt;
  &lt;button class="checkout"&gt;Checkout&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>The update in the form goes to update.js.erb which has this</p>

<pre><code>    &lt;% if @cart.errors.any? || @cart_item.errors.any? %&gt;
  alert("Not valid.");
&lt;%else%&gt;
  $(".cart-text").html("&lt;%= escape_javascript(render 'layouts/cart_text')%&gt;")
  $(".cart-container").html("&lt;%= escape_javascript(render 'carts/carts_row')%&gt;")
&lt;%end%&gt;
</code></pre>

<p>And destroy in the form has a same destroy.js.erb</p>

<pre><code>&lt;% if @cart.errors.any? || @cart_item.errors.any? %&gt;
  alert("Not valid.");
&lt;%else%&gt;
  $(".cart-text").html("&lt;%= escape_javascript(render 'layouts/cart_text')%&gt;")
  $(".cart-container").html("&lt;%= escape_javascript(render 'carts/carts_row')%&gt;")
&lt;%end%&gt;
</code></pre>

<p>The update renders the carts_row.html.erb form properly.
When I destroy an item it renders the page with empty products and a checkout total at the bottom. When I refresh the page the correct amount of products in the shopping cart is displayed and everything is where it should be!</p>

<p>How is the render of update correct but render of destroy incorrect???</p>

<p>My carts_item controller has these two methods for the forms:</p>

<pre><code>  def update
    @cart = current_cart
    # finding cart_items by cart_id
    @cart_item = @cart.cart_items.find(params[:id])
    # @cart_items.order(:id)
    @cart_item.update_attributes(cart_item_params)
    @cart_items = @cart.cart_items.order(:id)
    # redirect 'cart_show_path'
  end

  def destroy
    @cart = current_cart
    @cart_item = @cart.cart_items.find(params[:id])
    @cart_item.destroy
    @cart_items = @cart.cart_items
  end
</code></pre>