title: Delete the respective row completely if acutal quantity goes to zero
body: <p>I want to delete the respective row completely if <code>tquantity = 0</code>.</p>
  
  <p>Find the screenshot for better understanding as below;</p>
  
  <p><a href="http://i.stack.imgur.com/eCLFF.png" rel="nofollow">screenshot.png</a></p>
  
  <p>index.html.erb</p>
  
  <pre><code>&lt;div class="col-md-10 col-md-offset-1"&gt;
  
          &lt;div class="table-responsive myTable"&gt;
  
              &lt;table class="table listing text-center"&gt;
                  &lt;tr class="tr-head"&gt;
                      &lt;td&gt;DESCRIPTION&lt;/td&gt;
                      &lt;td&gt;COLOR&lt;/td&gt;
                      &lt;td&gt;QUANTITY&lt;/td&gt;
                      &lt;td&gt;RETAIL PRICE&lt;/td&gt;
                      &lt;td&gt;TOTAL AMOUNT&lt;/td&gt;
                      &lt;td&gt;CARTON NO&lt;/td&gt;
                      &lt;td&gt;CUSTOMER 1&lt;/td&gt;
                      &lt;td&gt;CUSTOMER 2&lt;/td&gt;
                      &lt;td&gt;ACTUAL QUANTITY&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;% @purchases.each do |purchase| %&gt;
  
                  &lt;tr class="tr-&lt;%= cycle('odd', 'even') %&gt;"&gt;
  
                      &lt;td class="col-2"&gt;&lt;%= purchase.description %&gt;&lt;/td&gt;
                      &lt;td class="col-1"&gt;&lt;%= purchase.color %&gt;&lt;/td&gt;
                      &lt;td class="col-2"&gt;&lt;%= purchase.quantity %&gt;&lt;/td&gt;
                      &lt;td class="col-2"&gt;&lt;%= number_with_precision(purchase.rprice, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;        
                      &lt;td class="col-2"&gt;&lt;%= number_with_precision(purchase.tamount, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;  
                      &lt;td class="col-2"&gt;&lt;%= purchase.cartonno %&gt;&lt;/td&gt;
                      &lt;td class="col-2"&gt;&lt;%= purchase.cus1 %&gt;&lt;/td&gt;
                      &lt;td class="col-2"&gt;&lt;%= purchase.cus2 %&gt;&lt;/td&gt;
                      &lt;td class="col-2"&gt;&lt;%= tquantity = purchase.quantity - purchase.cus1 - purchase.cus2 %&gt;&lt;/td&gt;
  
                  &lt;/tr&gt;
  
                  &lt;% end %&gt;
  
              &lt;/table&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>purchases_controller.rb</p>
  
  <pre><code>class PurchasesController &lt; ApplicationController
          before_action :set_purchase, only: [:show, :edit, :update, :destroy]
  
    # GET /Stockings
    # GET /deldetails.json
    def index
      #@purchases = Purchase.all
      @purchases = Purchase.where("tquantity !=?", 0)
    end
  
    def import
      Purchase.import(params[:file])
      redirect_to purchases_url, notice: "Purchases imported."
    end
  
    # GET /purchases/1
    # GET /purchases/1.json
    def show
    end
  
    # GET /purchases/new
    def new
      @purchase = Purchase.new
    end
  
    # GET /purchases/1/edit
    def edit
    end
  
    # POST /purchases
    # POST /purchases.json
    def create
      @purchase = Purchase.new(purchase_params)
  
      respond_to do |format|
        if @purchase.save
          format.html { redirect_to @purchase, notice: 'Purchase was successfully created.' }
          format.json { render :show, status: :created, location: @purchase }
        else
          format.html { render :new }
          format.json { render json: @purchase.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /purchases/1
    # PATCH/PUT /purchases/1.json
    def update
      respond_to do |format|
        if @purchase.update(purchase_params)
          format.html { redirect_to @purchase, notice: 'Purchase was successfully updated.' }
          format.json { render :show, status: :ok, location: @purchase }
        else
          format.html { render :edit }
          format.json { render json: @purchase.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /purchases/1
    # DELETE /purchases/1.json
    def destroy
      @purchase.destroy
      respond_to do |format|
        format.html { redirect_to purchases_url, notice: 'Purchase was successfully destroyed.' }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_purchase
        @purchase = Purchase.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def purchase_params
        params.require(:purchase).permit(:season, :category, :articleno, :description, :color, :quantity, :rprice, :tamount, :cartonno, :cus1, :cus2, :tquantity )
      end
  end
  </code></pre>
  
  <p>purchase.rb</p>
  
  <pre><code>class Purchase &lt; ActiveRecord::Base
  
      def self.import(file)
          CSV.foreach(file.path, headers: true) do |row|
              Purchase.create! row.to_hash
          end
      end
  end
  </code></pre>
  
  <p>Do I need to use SQL WHERE clause, and if yes, then how would I obtain the desired result?</p>