保持后代复选框的两个参数与父项关联input_field
Hold both params of Decendant checkbox accociate with parent input_field
有一个 select_tag
到 select 的客户。当用户 select 编辑了一个客户时,它会在 select_tag
.
下面生成一个子 checkbox_from
用户可以 select 一个客户并选中两个客户或其中一个客户的后代复选框。
如果用户select只有一个客户然后搜索,它会得到结果并且select_tag
value(param) 刷新后也会保存在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
这与您之前的问题相反。
你的check_box_tag
参数名是'organization_children'
,所以会传入params[:organization_children]
。您在控制器中正确访问它,在视图中执行相同的操作:
= check_box_tag "organization_children", "true", params[:organization_children].present?
有一个 select_tag
到 select 的客户。当用户 select 编辑了一个客户时,它会在 select_tag
.
用户可以 select 一个客户并选中两个客户或其中一个客户的后代复选框。
如果用户select只有一个客户然后搜索,它会得到结果并且select_tag
value(param) 刷新后也会保存在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
这与您之前的问题相反。
你的check_box_tag
参数名是'organization_children'
,所以会传入params[:organization_children]
。您在控制器中正确访问它,在视图中执行相同的操作:
= check_box_tag "organization_children", "true", params[:organization_children].present?