Hide table records temporarily in rails 4.2
<p>I would like to hide some of the records of the statement temporarily with updated balance. </p>

<p>Please refer the screen-shot for better understanding as shown below;</p>

<p><a href="https://i.stack.imgur.com/zubCZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zubCZ.png" alt="screenshot.png"></a></p>

<p>What I want is, when I clicked the hide button, it should hide the row completely and the balance must be carried forward and When <strong>Show all</strong> is clicked it must show all the records.</p>

<p>I have created hidden field in the table and written the hide_xvaziri method in the controller but confused with the hide button_to function in order to have, get '/xvaziri/:id/hide', to: 'xvaziris#hide_xvaziri'</p>

<p>20160729062246_add_hidden_to_xvaziris.rb</p>

<pre><code>class AddHiddenToXvaziris &lt; ActiveRecord::Migration

    def change
        add_column :xvaziris, :hidden, :boolean, :default =&gt; false  
    end

end
</code></pre>

<p>xvaziris_controller.rb    </p>

<pre><code>class XvazirisController &lt; ApplicationController
    before_action :set_xvaziri, only: [:show, :edit, :update, :destroy]


    def index
        @xvaziris = Xvaziri.find_by hidden: false
        @xvaziris = Xvaziri.search(params[:search])

        respond_to do |format|
            format.js
            format.html 
        end 
    end

    def import
        Xvaziri.import(params[:file])
        redirect_to xvaziris_url, notice: "Xvaziris imported."
    end

    def show
    end

    def new
        @xvaziri = Xvaziri.new
    end

    def create
        @xvaziri = Xvaziri.new(xvaziri)
        if
            @xvaziri.save
            flash[:notice] = 'Xvaziri Created'
            redirect_to @xvaziri
        else
            render 'new'
        end
    end

    def edit
    end

    def update
        if @xvaziri.update(xvaziri)
            flash[:notice] = 'Xvaziri Updated'
            redirect_to @xvaziri
        else
            render 'edit'
        end

    end

    def destroy
        @xvaziri.destroy
        flash[:notice] = 'Xvaziri was successfully destroyed.'
        redirect_to xvaziris_url    
    end

    def hide_xvaziri
        @xvaziri = Xvaziri.find(params[:id])
        @xvaziri.hidden = true
        flash[:notice] = 'Xvaziri was successfully hidden.'
        redirect_to xvaziris_url    
    end

    def reset_filter
        xvaziris = Xvaziri.all
        xvaziris.each do |xvaziri|
            xvaziri.hidden = false
        end
        redirect_to xvaziris_url
    end

    private
    # Use callbacks to share common setup or constraints between actions.
    def set_xvaziri
        @xvaziri = Xvaziri.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def xvaziri
        params.require(:xvaziri).permit(:date, :description, :amount, :discount, :paid)
    end

end
</code></pre>

<p>index.html.erb</p>

<pre><code>&lt;div class="row"&gt;

        &lt;div class="col-md-10 col-md-offset-1"&gt;

            &lt;div class="table-responsive myTable"&gt;

                &lt;table id = "kola" class="table listing text-center"&gt;
                    &lt;thead&gt;
                    &lt;tr class="tr-head"&gt;
                        &lt;td&gt;Description&lt;/td&gt;
                        &lt;td&gt;Amount&lt;/td&gt;
                        &lt;td&gt;Discount&lt;/td&gt;
                        &lt;td&gt;Paid&lt;/td&gt;
                        &lt;td&gt;Balance&lt;/td&gt;
                        &lt;td&gt;Button&lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;/thead&gt;

                    &lt;tbody&gt;              
                        &lt;%= render @xvaziris %&gt;
                    &lt;/tbody&gt;
                    &lt;/table&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;


&lt;%= link_to "Show all", xvaziri_resetfilter_path %&gt;
</code></pre>

<p>_xvaziri.html.erb</p>

<pre><code>&lt;tr   class="tr-&lt;%= cycle('odd', 'even') %&gt;"&gt;

    &lt;td class="col-3"&gt;&lt;%= span_with_possibly_red_color xvaziri.description %&gt;&lt;/td&gt;


    &lt;td class="col-1"&gt;&lt;%= number_with_precision(xvaziri.amount, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;

    &lt;td class="col-1 neg"&gt;&lt;%= number_with_precision(xvaziri.discount, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;

    &lt;td class="col-1 neg"&gt;&lt;%= number_with_precision(xvaziri.paid, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;


    &lt;% @balance += xvaziri.amount.to_f - xvaziri.discount.to_f - xvaziri.paid.to_f %&gt;

    &lt;% color = @balance &gt;= 0 ? "pos" : "neg" %&gt;

    &lt;td class="col-1 &lt;%= color %&gt;"&gt;&lt;%= number_with_precision(@balance.abs, :delimiter =&gt; ",", :precision =&gt; 2) %&gt;&lt;/td&gt;

    &lt;td class="col-1"&gt;&lt;%= button_to "Hide", '#', :method =&gt; "get" %&gt;&lt;/td&gt;

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

<p>routes.rb</p>

<pre><code>Rails.application.routes.draw do


    root 'xvaziris#index'

    resources :xvaziris do 
        collection { post :import }
    end

    get '/xvaziri/:id/hide', to: 'xvaziris#hide_xvaziri'

    get '/xvaziri/resetfilter', to: 'xvaziris#reset_filter'

end
</code></pre>

<p>Any suggestions are most welcome.</p>

<p>Thank you in advance.</p>