我使用过rails4-autocomplete gem,我在自动填充搜索表单中显示提示时出现问题。我看不到任何提示。
我的 index.html.erb
<%= form_tag(products_path, :method => "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], class: "search-query", placeholder: "namesearch", type: "search", data: {autocomplete: products_autocomplete_product_title_path} %>
<%= submit_tag "Search" %>
<%end%>
<script type="text/javascript" charset="utf-8">
$('#search').bind('railsAutocomplete.select', function(event, data){
$('#search-form').submit()
});
</script>
我在控制器,模型和application.js中添加了需求代码
我的 application.js - 清单
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require jquery-ui
//= require autocomplete-rails
//= require cocoon
//= require turbolinks
//= require_tree .
我的 products.scss
.ui-autocomplete {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
float: left;
display: none;
min-width: 160px;
_width: 160px;
padding: 4px 0;
margin: 2px 0 0 0;
list-style: none;
background-color: #ffffff;
border-color: #ccc;
border-color: rgba(0, 0, 0, 0.2);
border-style: solid;
border-width: 1px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
*border-right-width: 2px;
*border-bottom-width: 2px;
.ui-menu-item > a.ui-corner-all {
display: block;
padding: 3px 15px;
clear: both;
font-weight: normal;
line-height: 18px;
color: #555555;
white-space: nowrap;
}
}
.ui-widget-content .ui-state-focus {
color: #ffffff;
text-decoration: none;
background-color: #0088cc;
border-radius: 0px;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
background-image: none;
}
我的 routes.rb
...
resources :products
get 'products/autocomplete_product_title'
...
我的控制器
...
autocomplete :product, :title, :full => true
def index
@products = Product.all
if params[:search]
@products = Product.title_like("%#{params[:search]}%").order('title')
end
end
...
我的模型
...
scope :title_like, -> (title) { where("title like ?", title)}
...
我不知道我做错了什么
感谢您的时间!