0

我正在尝试在 Rails 中自动完成。因为我在 Rails 中的菜鸟无法将这个苗条的代码转换为 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"
4

1 回答 1

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/

享受。

于 2013-10-31T07:32:48.517 回答