application.html
[url]http://docs.jquery.com/Plugins/autocomplete[/url]
/view/products/_form.html
products_controller.rb
routes.rb
其实支持中文,网上也有教程。
在jquery.autocomplete.js的194行左右的
希望对你有帮助, 我折腾好久。下面有这个autocomplete 的rails 3 demo
[b]推荐阅读[/b][url]http://compdocjos.blogspot.in/2010/11/creating-autocompleting-association.html[/url]
[url]http://docs.jquery.com/Plugins/autocomplete[/url]
<!DOCTYPE html>
<html>
<head>
<title>AotoComplete</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag 'AutoComplete/jquery','AutoComplete/jquery.autocomplete','AutoComplete/jquery.bgiframe.min' %>
<%= stylesheet_link_tag 'AutoComplete/jquery.autocomplete','AutoComplete/main' %>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
</body>
</html>
/view/products/_form.html
<script>
$(document).ready(function(){
$("#product_name").autocomplete('/products/search',{matchContains: false})}
</script>
products_controller.rb
....
def search
key_word = params[:q]
# Product.limit(params[:limit])
@product_names = Product.connection.select_values("select name from products where name like '%#{key_word}%'")
respond_to do |format|
format.html { render :text => @product_names.join("\n")}
end
end
...
routes.rb
resources :products do
collection do
get 'search'
end
end
其实支持中文,网上也有教程。
在jquery.autocomplete.js的194行左右的
.bind("unautocomplete", function() {
select.unbind();
$input.unbind();
$(input.form).unbind(".autocomplete"); # 下面添加
}).bind("input", function() {
// @hack by liqt:support for inputing chinese characters in firefox
onChange(0, true);
希望对你有帮助, 我折腾好久。下面有这个autocomplete 的rails 3 demo
[b]推荐阅读[/b][url]http://compdocjos.blogspot.in/2010/11/creating-autocompleting-association.html[/url]