有一个select_tag
用于选择客户。用户选择客户后,它将在select_tag
下方生成一个子checkbox _。
用户可以选择一个客户,然后选中“后代”复选框或两个客户,或者仅选中一个客户。
如果用户仅选择一个客户然后进行搜索,它将获得结果,并且select_tag
值(参数)在刷新后也会保留在select标签中。
但是问题是,如果我尝试同时获取select_tag
和checkbox_tag
数据,它将生成数据,但是两个参数都消失了。搜索结果后,我需要同时保留两个参数。
这是我的观点
.row
.col-md-3
= label_tag "Customer/Supplier Name"
= select_tag "search_customer_supplier[id]", options_from_collection_for_select(Organization.customers_and_suppliers, :id, :name, params.dig('search_customer_supplier', 'id')), class: "form-control parent_class chosen-select", id: "search_registered_customers", include_blank: true
.col-md-10.small_scale_margin-top2#check_children_wrapper.hide
= label_tag "Descendent"
= check_box_tag "organization_children", "true", params.dig('search_customer_supplier', 'organization_children')&.include?('true')
这是我关于复选框的控制器代码
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
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?
customer_report = params[:search_customer_supplier].map { |k, v| "#{k}:#{v}" if v.present? }.compact
答案 0 :(得分:0)
这与您先前的问题相反。
您的check_box_tag
的参数名称为'organization_children'
,因此它将在params[:organization_children]
中传递。您可以在控制器中正确访问它,在视图中执行相同的操作:
= check_box_tag "organization_children", "true", params[:organization_children].present?