How to hold the checkbox params in rails after search

好久不见. 提交于 2019-12-24 20:45:56

问题


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.Realoding all over the page, then Checkbox true values are gone. How to hold the params after refreshing the page

   .row
            .col-md-3
              = check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]","CUS", false
              = label_tag "Organizational Customer"
            .col-md-3
              = check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]", "SUP", false, class: "first_resolution"
              = label_tag "Organzational Supplier"
            .col-md-3
              = check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]", "INDCUS", false, class: "first_resolution"
              = label_tag "Individual Customer"
            .col-md-3
              = check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]", "INDSUP", false, class: "first_resolution"
              = label_tag "Individual Supplier"

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
      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?

      @all_address = params[:all_address].to_bool if params[:all_address].present?
      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

回答1:


You can use check for the submitted value on the third param:

check_box_tag 'search_customer_supplier[accounts_dealer_types.dealer_code]', 'CUS', params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] == 'CUS'



回答2:


After that i aroused another problem when i paginate into 2nd page.

This is the output when it paginate to the next pages. https://i.stack.imgur.com/5MDpq.png

Below i mentioned the code(in controller),i think it'd be the query that called.when paginating.

 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?


来源:https://stackoverflow.com/questions/56133786/how-to-hold-the-checkbox-params-in-rails-after-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!