Links
auto_complete
Categories
auto_complete
Example:
# Controller
class BlogController < ApplicationController
auto_complete_for :post, :title
end
# View
<%= text_field_with_auto_complete :post, title %>
By default, auto_complete_for limits the results to 10 entries,
and sorts by the given field.
auto_complete_for takes a third parameter, an options hash to
the find method used to search for the records:
auto_complete_for :post, :title, :limit => 15, :order => 'created_at DESC'
For more examples, see script.aculo.us:
* http://script.aculo.us/demos/ajax/autocompleter
* http://script.aculo.us/demos/ajax/autocompleter_customized
Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license
Vitals
| Repository | git://github.com/rails/auto_complete.git |
|---|---|
| License | Rails' (MIT) |
| Tags |
auto complete technique view
|
| Rating | (34 votes) |
| Created | 6 November 2007 |
Comments
-
Great to have the leaders of RAILS, like David, committed to making transitions in the framework go smoothly. The effort to post this plugin well in advance of RAILS 2.0 - which will no longer natively have the auto complete functionality - is a great example of the quality of the RAILS community.
-
David thanks for the plugin. I have not been able to make it work though. I've made sure everything is in the right place in the controller and views. I don't get any errors in fact I get nothing at all. I have also downloaded the latest .js files with no success. Would appreciate any advice. Thank you again.
-
The plugin does not work!!!
No error messages, no documentation available and nothing found in google, if get it working consider yourself lucky.
It used to work like a charm in rails 1.2... :'(
-
Hej. If you have problems to get it work take a look at mini tutorial ho wto use this plugin in Rails > 2.0
http://trix.pl/blog/ruby-on-rails/auto-complete-for-rails-2-0-tutorial
-
Great plugin -- thanks. It's small and focused.
-
This is all the documentation there is? gulp I miss Rails 1.2.
-
Demos url changed: http://demo.script.aculo.us/ajax/autocompleter_customized
-
I tried very hard to get this installed using the command: script/plugin install git://github.com/rails/auto_complete.git I always got an error that plugin not found. I am quite confident that git work on my machine. So what I did was this: 1. Switched to the vendor/plugins directory 2. Cloned the git repository there via: git clone git://github.com/rails/auto_complete.git This had the same affect as installing the plugin. Hopefully, this helps. If anyone has any idea why it didnt install properly the first time around, do let me know.
-
Great plugin ... working perfectly Thanks :)
-
Things you'll need since everyone else was too lazy to write down:
Example model is 'list' Example field is 'name'
Controller
auto_complete_for :list, :name skip_before_filter :verify_authenticity_token, :only => [:auto_complete_for_list_name]
view (edit.html.erb)
<%= javascript_include_tag :all, :cache => true %> <% form_for(@list) do |f| %> <%= f.error_messages %>
<p>
New <%= f.label :name %>:&nbsp;<%= text_field_with_auto_complete :list, :name %> <%= f.submit "Update" %><% end %>
layout
<%= javascript_include_tag :defaults %>
routes.rb
map.auto_complete ':controller/:action',
:requirements => { :action => /auto_complete_for_\S+/ }, :conditions => { :method => :get } -
Ajax is not defined ingredients()()ingredients (line 49) [Break on this error] var ingredient_name_auto_completer = new.../auto_complete_for_ingredient_name', {})
do I need to include something?
-
This did not work out of the box!
First I got a js error about a missing Ajax object. I solved that by adding <%= javascript_include_tag :defaults %> to my view.
Then I got "ActionController::InvalidAuthenticityToken" which I solved by adding protect_from_forgery :only => [:create, :update, :destroy] to my controller.
With those two adjustments... great plugin! :)
-
I'm trying to use an autocomplete twice on the same page, but only the first one renders and functions.
I'm using the Autocomplete Plugin and Rails 2.1
Thanks, Andy
-
Thank you David for the extra notes on how to get auto_complete working - the documentation included with it is very sketchy and incomplete. I think now that I'm nearly there but I still have one problem.
The route set up above clearly expects requests from the Javascript code to be GETs. In my application however the Ajax.Autocompleter insists on sending POSTs which seems in appropriate. POSTs are for creating something and all it's trying to do is get some information. Obviously they also don't match the route.
Should the autocompleter be sending POSTs? If not, how do you get it to use GETs instead?
TIA, John

