搜索工作正常,但问题是当我根据结果打印excel报告时,它显示数据库中的所有值,筛选器不起作用。遍及整个页面,则复选框为true值不见了刷新页面后如何保持参数
.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"
这是我的控制器,
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
答案 0 :(得分:0)
您可以在第三个参数上使用check来检查提交的值:
check_box_tag 'search_customer_supplier[accounts_dealer_types.dealer_code]', 'CUS', params[:search_customer_supplier]['accounts_dealer_types.dealer_code'] == 'CUS'
答案 1 :(得分:0)
此后,我翻到第二页时又引起了另一个问题。
这是当分页到下一页时的输出。 https://i.stack.imgur.com/5MDpq.png
下面我提到了代码(在控制器中),我认为这是在分页时调用的查询。
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?