I want to use jQuery UI autocomplete function in my rails app. I get a example in jQuery website and want to make it in my rails app. jquery-rails
and jquery-ui-rails
all have been installed.
I added the below codes to application.js
$(function() {
var availableTags = [
"C",
"C++",
"Clojure",
"COBOL",
"Haskell",
"Java",
"JavaScript",
"Perl",
"PHP",
"Python",
"Ruby",
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
add some codes to show.html.erb
:
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
but doesn't autocomplete when I input something(like: "ja"..)
Anyone can help me, thanks in advance!
Try this:
In your gemfile
gem 'rails3-jquery-autocomplete'
`bundle install`
In your application.js
//= require autocomplete-rails
In your controller
autocomplete :model_name, :column_name, :full => true
In your routes
resources :controller_name do
get :autocomplete_model_name_column_name, :on => :collection
end
In your view
<%= autocomplete_field_tag 'column_name', '', autocomplete_model_name_column_name_controller_name_path %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.