Rails渲染不使用searchkick打开新页面

时间:2015-11-21 15:19:43

标签: ruby-on-rails

我正在尝试制作搜索结果页面。但是,当我点击搜索控制台状态时,我得到了正确的ID,但结果页面没有打开。

我有我的控制器

  def search
    @events = Newevent.search params[:search]
    render 'events/results'
  end

我也将此作为我的搜索表单

  <div class="input-group input-group-lg">
    <%= text_field_tag :search, params[:search], class: "form-control", autocomplete: "off" %>
    <div class="input-group-btn">
      <%= submit_tag "Search", class: "btn btn-primary" %>
    </div>
  </div>
<% end %>

这是在结果html.erb

<% @events.each do |event| %>
<h1>Test</h1>
<%= event.eventname %>
<% end %>

这是我开始搜索时控制台所说的内容

Started GET "/search_events?utf8=%E2%9C%93&search=capital&commit=Search" for ::1 at 2015-11-21 15:18:33 +0000
Processing by NeweventsController#search as JS
  Parameters: {"utf8"=>"✓", "search"=>"capital", "commit"=>"Search"}
  User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["id", 2]]
  Newevent Search (9.8ms)  curl http://localhost:9200/newevents_development/_search?pretty -d '{"query":{"dis_max":{"queries":[{"match":{"_all":{"query":"capital","operator":"and","boost":10,"analyzer":"searchkick_search"}}},{"match":{"_all":{"query":"capital","operator":"and","boost":10,"analyzer":"searchkick_search2"}}},{"match":{"_all":{"query":"capital","operator":"and","boost":1,"analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}},{"match":{"_all":{"query":"capital","operator":"and","boost":1,"analyzer":"searchkick_search2","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}}]}},"size":100000,"from":0,"fields":[]}'
  Newevent Load (0.5ms)  SELECT "newevents".* FROM "newevents" WHERE "newevents"."id" = 20
  Rendered events/results.html.erb within layouts/application (1.6ms)
  Rendered layouts/_navigation.html.erb (0.1ms)
  Rendered layouts/_messages.html.erb (0.1ms)
  Rendered layouts/_footer.html.erb (0.0ms)
Completed 200 OK in 93ms (Views: 79.5ms | Searchkick: 9.8ms | ActiveRecord: 1.0ms)

1 个答案:

答案 0 :(得分:1)

根据您服务器的日志,我认为您将搜索表单设置为远程表单(您会在remote: true标记中看到form_for

Processing by NeweventsController#search as JS

您是否在上一行中看到了文字:为JS 。那是因为你提交了一份远程表格。这意味着当您提交表单时,表单将调用ajax到服务器等待服务器返回js代码以在客户端运行。

要解决您的问题,只需删除remote: true标记中的form_for即可,一切正常;)