搜索工作正常。但是我的问题是,当我选中一个复选框并进行搜索时,它将获得我的结果,刷新后还存在复选框的真实状态。但是当选中两个或多个复选框时,它不保存真实状态。我需要保持那些真实状态
我的问题是我有4个复选框。当我一次选中两个或多个复选框时,它将得到我的结果,然后消失了真实状态。我需要保留这些状态才能在页面刷新后打印报告。
这是我当前对四个复选框的看法。
.row
.col-md-3
= check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]","CUS", params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] == 'CUS'
= label_tag "Organizational Customer"
.col-md-3
= check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]", "SUP", params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] == 'SUP'
= label_tag "Organzational Supplier"
col-md-3
= check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]", "INDCUS", params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] == 'INDCUS'
= label_tag "Individual Customer"
.col-md-3
= check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]", "INDSUP", params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] == 'INDSUP'
= label_tag "Individual Supplier"
这是我的控制人
def customer_supplier_report
Organization
Address
ContactNumber
refined_query = ""
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] = 4000
@customer_reports = Organization.search(params)
@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
答案 0 :(得分:0)
字段名称search_customer_supplier[accounts_dealer_types.dealer_code][]
表示params[:search_customer_supplier]['accounts_dealer_types.dealer_code']
是一个数组,因此您应该检查它是否包含:
check_box_tag "search_customer_supplier[accounts_dealer_types.dealer_code][]",
"CUS",
params.dig(:search_customer_supplier, 'accounts_dealer_types.dealer_code')&.include?('CUS')