Agile Web Development

Build it. Launch it. Love it.



# Controller
class BlogController < ApplicationController
auto_complete_for :post, :title

# 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

Copyright (c) 2007 David Heinemeier Hansson, released under the MIT license


Repository git://
License Rails' (MIT)
Rating (39 votes)
Created 6 November 2007


  • JBB
    4 December 2007

    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.

  • Avatar
    16 December 2007

    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.

  • John
    27 December 2007

    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... :'(

  • Avatar
    29 January 2008

    Hej. If you have problems to get it work take a look at mini tutorial ho wto use this plugin in Rails > 2.0

  • Avatar
    16 July 2008

    Great plugin -- thanks. It's small and focused.

  • Avatar
    J. Kelly
    15 August 2008

    This is all the documentation there is? gulp I miss Rails 1.2.

  • cris
    13 January 2009

    Demos url changed:

  • 23 January 2009

    I tried very hard to get this installed using the command: script/plugin install 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:// 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.
  • ali
    28 January 2009

    Great plugin ... working perfectly Thanks :)

  • David
    18 March 2009

    Things you'll need since everyone else was too lazy to write down:

    Example model is 'list' Example field is 'name'


    autocompletefor :list, :name skipbeforefilter :verifyauthenticitytoken, :only => [:autocompleteforlistname]

    view (edit.html.erb)

    <%= javascriptincludetag :all, :cache => true %> <% form_for(@list) do |f| %> <%= f.error_messages %>

    <p> New <%= f.label :name %>:&nbsp;<%= textfieldwithautocomplete :list, :name %> <%= f.submit "Update" %> <% end %>


    <%= javascriptincludetag :defaults %>


    map.auto_complete ':controller/:action', :requirements => { :action => /autocompletefor_\S+/ }, :conditions => { :method => :get }

  • Avatar
    18 April 2009

    Ajax is not defined ingredients()()ingredients (line 49) [Break on this error] var ingredientnameautocompleter = new.../autocompleteforingredient_name', {})

    do I need to include something?

  • Avatar
    22 April 2009

    This did not work out of the box!

    First I got a js error about a missing Ajax object. I solved that by adding <%= javascriptincludetag :defaults %> to my view.

    Then I got "ActionController::InvalidAuthenticityToken" which I solved by adding protectfromforgery :only => [:create, :update, :destroy] to my controller.

    With those two adjustments... great plugin! :)

  • Avatar
    Andy Milk
    2 June 2009

    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

  • Avatar
    John Winters
    7 August 2009

    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

Add a comment