我在rails中尝试自动完成功能。因为我在轨道上的noob无法将这个超薄的代码转换为erb所以任何人都可以帮助我!!!
第一个苗条文件
# app/views/books/index.html.slim
= form_tag books_path, class: "form-inline", method: :get do
.form-group
= text_field_tag :query, params[:query], class: "form-control"
'
= submit_tag "Search", class: "btn btn-primary"
- if params[:query].present?
'
= link_to "clear", books_path
第二个苗条文件
#app/views/layouts/application.html.slim
= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.9.3/ typeahead.min.js"
第三个苗条文件
# app/views/books/index.html.slim
= form_tag books_path, class: "form-inline", method: :get do
.input-group.input-group-lg
- if params[:query].present?
.input-group-btn
= link_to "clear", books_path, class: "btn btn-default"
= text_field_tag :query, params[:query], class: "form-control", id: "book_search", autocomplete: "off"
.input-group-btn
= submit_tag "Search", class: "btn btn-primary"
答案 0 :(得分:0)
首先:
<%=form_tag books_path, class: "form-inline", method: :get do %>
<div class="form-group">
<%= text_field_tag :query, params[:query], class: "form-control" %>
<%= submit_tag "Search", class: "btn btn-primary" %>
<% if params[:query].present? %>
<%= link_to "clear", books_path %>
<% end %>
</div>
第二
<%= javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.9.3/ typeahead.min.js" %>
第三
<%= form_tag books_path, class: "form-inline", method: :get do %>
<div class="input-group input-group-lg" >
<% if params[:query].present? %>
<div class="input-group-btn">
<%= link_to "clear", books_path, class: "btn btn-default" %>
</div>
<%= text_field_tag :query, params[:query], class: "form-control", id: "book_search", autocomplete: "off" %>
<div class="input-group-btn">
<%= submit_tag "Search", class: "btn btn-primary" %>
</div>
<% end %>
</div>
您可以随时在此处验证 - http://html2slim.herokuapp.com/
享受。