Rails,rails内部的单独搜索功能

时间:2014-11-21 12:00:18

标签: ruby-on-rails forms

我想在表单中嵌入搜索功能,以便用户可以搜索并选择要提交的产品以及显示可用性的日期范围。我不确定在没有提交所有参数并尝试在控制器中处理它的最佳方法。我相信这样的东西有一个rails解决方案。

这是我想要实现的目标

=simple_form_for [:admin,availability_inspector] do |f|
    = f.text_field :start, type: :text, placeholder: "click to use the date-time picker", class: "form-control auto_picker"
    = f.text_field :finish, type: :text, placeholder: "click to use the date-time picker", class: "form-control auto_picker"
      Stock List Search
      =form_tag new_admin_availability_inspector_path, method: :get do
        =search_field_tag :querystr, params[:querystr], placeholder: "filter", class: "form-control"
        %span.input-group-btn
        =submit_tag "filter", name: nil, class: "btn btn-primary"
  -if @products.any?        
    %ul.list-group
      - @products.each do |product|
        = product.title
          = check_box_tag :product_id, product.id


=f.submit "filter", name: nil, class: "btn btn-primary"

因此,想法是,搜索和列出的项目,用户选择项目,并且使用日期字段范围,提交表单。

1 个答案:

答案 0 :(得分:0)

在名为products的表单中添加隐藏数组字段。在表单处理产品之外,通过Ajax调用搜索,选择和更新该隐藏字段。

检查这个link,它是一个类似但更简单的例子,因为他只想动态地添加地址,而你仍然首先通过Ajax处理产品搜索。请注意,他解决方案中唯一需要的部分是他如何通过JavaScript使用新字段更新表单,其余细节则无关紧要。