如何一次保持两个输入值参数

时间:2019-05-17 04:57:19

标签: ruby-on-rails ruby ruby-on-rails-4

我有两个输入标签。一个是select_tagcheckbox_tag

选择框用于选择客户名称,选择一个时,将显示另一个复选框以及点击事件。

如果仅选择一个客户而不选择一个客户,则进行搜索。搜索后保留客户名称选择参数。

但是,当我选择客户名称并同时选中了Decendents标签时,搜索将不会同时包含这两个参数。搜索之后,两个参数都消失了。搜索后我需要保存参数。

这是我的观点:

  .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", false

这是我的控制者:

  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

0 个答案:

没有答案