mardi 14 mai 2019

How to hold the checkbox true value in rails after search

The search is working fine but the problem is that when i print the excel report according to the result.it is showing all the values in the database, filter is not working then Checkbox true values are gone. How to hold the 'All address' checkbox params after refreshing the page.

This is my view

.col-md-3.small_scale_margin-top2
  = check_box_tag "all_address"
  = label_tag "Show All Addresses"

This is my controller

    if params[:search].present? or params[:excel_report].present?

      search_customer_supplier = params[:search_customer_supplier]

      if params[:organization_children].present? and search_customer_supplier["id"].present?
        organization_id = search_customer_supplier["id"]
        organization = Organization.find(organization_id)
        anchestor_ids = organization.anchestors.map{|o| o[:member].id }
        search_customer_supplier["id"] = "(#{anchestor_ids.join(' OR ')})" if anchestor_ids.any?
      end
      #puts "======================================================================"
      # puts params[:search_customer_supplier]['accounts_dealer_types.dealer_code']

      params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] = params[:search_customer_supplier]['accounts_dealer_types.dealer_code'].join(" OR ") if params[:search_customer_supplier]['accounts_dealer_types.dealer_code'].present?

      # puts params[:search_customer_supplier]['accounts_dealer_types.dealer_code']

      customer_report = params[:search_customer_supplier].map { |k, v| "#{k}:#{v}" if v.present? }.compact
    else
      customer_report = ["accounts_dealer_types.dealer_code:(CUS OR SUP OR INDCUS OR INDSUP)"]
    end

    @all_address = params[:all_address].to_bool if params[:all_address].present?
    refined_query += customer_report.join(" AND ")
    params[:query] = refined_query
    # params[:per_page] = 500
    @customer_reports = Organization.search(params)

    puts "========================================================="
      puts @customer_reports
    puts "========================================================="

    @account_managers = User.where(active: true)
    respond_to do |format|
      if params[:excel_report].present?
        request.format = "xls"
        format.xls { set_attachment_name "customer_supplier_report.xls" }
      else
        format.html
      end
    end

  end

In my controller this is the relevant part for the checkbox

@all_address = params[:all_address].to_bool if params[:all_address].present?

Aucun commentaire:

Enregistrer un commentaire