Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在表单中添加搜索功能_Javascript_Jquery_Ruby On Rails - Fatal编程技术网

Javascript 在表单中添加搜索功能

Javascript 在表单中添加搜索功能,javascript,jquery,ruby-on-rails,Javascript,Jquery,Ruby On Rails,我正在另一个表单中添加搜索功能。我想在另一个表单中搜索内容 Interest\u index.html.erb <%= form_for :interest, url: interest_index_path do |f| %> <p class="col-md-8" align="left"><%= f.submit "Save Schedule", class: "btn btn-primary btn-lg btn-block"%></p&

我正在另一个表单中添加搜索功能。我想在另一个表单中搜索内容

Interest\u index.html.erb

<%= form_for :interest, url: interest_index_path do |f| %>
    <p class="col-md-8" align="left"><%= f.submit "Save Schedule", class: "btn btn-primary btn-lg btn-block"%></p>
    <br>
    <div class="field form-group col-lg-12">
        <h1><%= f.label :interests, "Schedule" %></h1>
        <br>
        <div class="row inline">
         <%= form_tag interest_index_path, method: :get do %>
          <p>
          <div class="col-lg-offset-2 col-lg-7" id="one">
            <%= text_field_tag :search, params[:search], class: "form-control", placeholder: "Search" %>
          </div>
          <div id="two">
            <%= submit_tag "Search", name: nil, class: "btn btn-default" %>
          </div>
          </p>
        <% end %>
       </div> 

       <% @subjects.each do |subject| %>
        <div class="field">
          <p><h4><%= f.check_box :interests, {:multiple => true}, subject.id, nil %><%= subject.name %></h4></p>
        </div> 
       <% end %>
     </div> 
<% end %>
**利息模型**

class Interest < ActiveRecord::Base
searchkick

include Tire::Model::Search
include Tire::Model::Callbacks

def self.search(search)
    if search
        where('name LIKE ?', "%#{search}")
    else
        scoped
    end
end
end
class-Interest
主题模式

class Subject < ActiveRecord::Base
 has_many :posts
 has_many :users, through: :posts
 validates_presence_of :name
 validates_uniqueness_of :name
end
类主题
受试者\u控制者

class SubjectController < ApplicationController
  def index
   @subject = Subject.all.includes(:posts => [:user])
   @interests_array = []
   if current_user.interests != "null"
     JSON.parse(current_user.interests).each do |f|
       if Subject.find(f)
         @interests_array.push(Subject.find(f))
       end
   end
  end
 end
end
class SubjectController[:user])
@兴趣_数组=[]
如果当前用户感兴趣!=“空”
parse(current_user.interests)|
如果主题为。查找(f)
@兴趣数组推送(Subject.find(f))
结束
结束
结束
结束
结束

明白了,不需要嵌套表单。我也用错了型号

class SubjectController < ApplicationController
  def index
   @subject = Subject.all.includes(:posts => [:user])
   @interests_array = []
   if current_user.interests != "null"
     JSON.parse(current_user.interests).each do |f|
       if Subject.find(f)
         @interests_array.push(Subject.find(f))
       end
   end
  end
 end
end