简体   繁体   English

提交Elasticsearch时如何在搜索框中保留搜索框输入

[英]How to keep search box input in search box when submitted Elasticsearch

Using elastic search with searchkick on a rails 4 app.在 rails 4 应用程序上使用带有 searchkick 的弹性搜索。

I would like the input(query) the user types into the search box to stay there after the submit button is clicked and the page is redirected.我希望用户在搜索框中键入的输入(查询)在单击提交按钮并重定向页面后留在那里。 Every page of my app has a search bar so keeping the users input in the box would be great.我的应用程序的每个页面都有一个搜索栏,因此将用户输入保留在框中会很棒。 As of now the search box clears after submitting.截至目前,搜索框在提交后清除。

Having some trouble doing this.这样做有点麻烦。 Have tried a few different methods but nothing is working.尝试了几种不同的方法,但没有任何效果。 Here is my search bar view:这是我的搜索栏视图:

<%= form_tag articles_path, method: :get do %>
 <p>
  <%= text_field_tag :query, params[:query], style:"width:550px; height:34px;", :autofocus => true, class: "form-control" %><br>
  <%= submit_tag "Let's Find Out!", :name => nil, class: "btn btn-default", style: "margin-top:6px; margin-right: 10px;" %><%= submit_tag "Most Popular", :name => nil, class: "btn btn-default", style: "margin-top:6px; margin-left: 10px;" %>
 </p>
<% end %>

Any suggestions would be greatly appreciated.任何建议将不胜感激。

A couple quick suggestions:几个快速建议:

  1. drop the params[:query] in the session or a cookie and insert into your text_field_tag as the placeholder or value property.将 params[:query] 放在会话或 cookie 中,并作为占位符或值属性插入到您的 text_field_tag 中。 The obvious issue is that you'd manually have to clear it when necessary.明显的问题是您必须在必要时手动清除它。
  2. pass the params[:query] as a query string and grab it that way inserting into the text_field_tag as above.将 params[:query] 作为查询字符串传递并以这种方式将其插入 text_field_tag 中,如上所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM