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| %>
      <%= task_form.label :name, "Task:" %>
      <%= task_form.text_field_with_auto_complete :name, {},
          { :method => :get, :skip_style => true } %>
  <% 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 |


Install as a gem:

gem sources -a
sudo gem install repeated_auto_complete

… and in config/environment.rb: do |config|
  config.gem "repeated_auto_complete"

Install as a plugin:

script/plugin install git://

More information: