The auto_complete plugin refactored to support repeated fields and named scopes

(Updated June 2009)

This version of auto_complete will support text fields that are repeated more than once on a complex form. It allows you to call text_field_with_auto_complete on the form builder object yielded by fields_for or form_for. This will work for complex forms built with Rails 2.2 or earlier, and for the nested attributes feature introduced in Rails 2.3. Here's an example using nested attributes:

<% form_for @project do |project_form| %>
  <% project_form.fields_for :tasks do |task_form| %>
    <p>
      <%= task_form.label :name, "Task:" %>
      <%= task_form.text_field_with_auto_complete :name, {},
          { :method => :get, :skip_style => true } %>
    </p>
  <% end %>
<% end %>

It also allows you to provide a block to auto_complete_for in your controller that filters the drop down pick list in some custom way. For example, this block would display task names for the project the user had selected elsewhere on the same form, using a named scope by_project:

auto_complete_for :task, :name do | items, params |
  items.by_project(params['project'])
end

Code:  http://github.com/patshaughnessy/auto_complete

Install as a gem:

gem sources -a http://gemcutter.org
sudo gem install repeated_auto_complete

… and in config/environment.rb:

Rails::Initializer.run do |config|
…
  config.gem "repeated_auto_complete"
…
end

Install as a plugin:

script/plugin install git://github.com/patshaughnessy/auto_complete.git

More information: