title: best way to redirect to another action in controller
body: <p>I am building a "shopping cart" and i am looking to allow the user to update quantities of an item in the cart. I have a remove link for the cart item, but the user could technically put the quantity to "0" rather than hitting the remove button. So on "update" i want to check if @cart.item.quantity == 0, and if so, then just redirect to the destroy action in the controller.</p>
  
  <p>what is the cleanest solution to this? Here is what i tried but it doesn't work, and i am thinking its not the cleanest approach... </p>
  
  <p>In my controller:</p>
  
  <pre><code>  def update
      if @cart_item.quantity == 0
        render action: :destroy
      else
        respond_to do |format|
          if @cart_item.update(cart_item_params)
            format.js#on { head :no_content }
          else
            format.json { render json: @cart_item.errors, status: :unprocessable_entity }
          end
        end
      end
    end
  
    def destroy
      @cart_item.destroy
      respond_to do |format|
        format.js
      end
    end
  </code></pre>