Problem getting started with auto_complete

I'm a n00b with Rails, and I'm trying to implement basic autocomplete according to Agile Web Dev w/Rails 3rd edition (p. 584-586) I've installed the auto_complete plugin, added the statement "auto_complete_for :game, :publisher" to my controller (Game is the model, publisher the field I want autocompletion on), and and put the following in my view template:

    <%= f.label :publisher %><br />     <%= f.text_field :publisher, :size => 60 %>     <div class="auto_complete" id="game_publisher_auto_complete"></

    <%= auto_complete_field :game_publisher, :url => {:action => 'autocomplete_publisher'} %>

and as suggested in another group, added: map.resources :games, :collection => {:autocomplete_for_game_publisher => get} to my routes file

I have the stylesheet included and (I think) all of the Javascript libraries required.

The 1st error I get is :

undefined method `auto_complete_for' for GamesController:Class

and when I comment that line out, I get:

undefined method `auto_complete_field' for #<ActionView::Base: 0x47d2284>

What am I missing?

thanks in advance, geoff

That syntax was removed from Rails in 1.2.6 and moved to a plugin.

Here is one plugin that can be used

Hi... I've been working on a gem recently that allows you to generate scaffolding for auto_complete behavior, among other things. The idea was to make it easier to get started with using a plugin like auto_complete.

See: Auto_complete scaffolding - Pat Shaughnessy

Based on your error messages, it looks like you may not have installed the auto_complete plugin properly. You should also be using a macro/ helper called "text_field_with_auto_complete", and not "auto_complete_field". Not sure how old your book is.

My article has a step-by-step example that hopefully will be helpful... - pat

Just for reference, Agile Web Dev w/ Rails, 3rd Ed, Copyright 2009, P3.0 Printing, July 2009

Page 583 includes:

  "<%= auto_complete_field :user_favorite_language,           :url=>{:action=>'autocomplete_favorite_language'}, :tokens => ',' %>"

The same code appears in the source .tgz for the book (http://

There is no mention of this issue in the errata ( titles/rails3/errata).

The lesson here is: When using gems and plugins always follow the instructions delivered with the code.

Pat, your view_mapper is very cool - worked like a charm, but even after re-installing the auto_complete plugin (/vendor/plugins/) and generating the view scaffolding, I'm still getting the undefined method error: undefined method `auto_complete_for' for GamesController:Class in my controller.

I'm using Ruby 1.8.6, Rails 2.3.3

According to everyone's responses and what I've found searching for answers, this should work but it doesn't in my environment...

thanks for any input, geoff

I'm happy to try to help you debug this one... if you want TAR up some/ all of the code and email it to me:

... however, I expect if I do run your code on my machine it will work no problem. My guess is there's some environment issue you have.

The first thing I would try is to put a "puts" statement in the vendor/ plugins/auto_complete/init.rb file. The only explanation for "auto_complete_for" not being defined is for some reason if the plugin isn't being loaded when the Rails environment is initialized as your app is started. You should see a messaged displayed in the console/log when init.rb is loaded for your copy of auto_complete.

The second thing I would do is create a brand new, vanilla rails app, install the auto_complete plugin into it and then create an auto_complete form and see if it's works for you. You can follow the step by step instructions in my "auto complete scaffolding" article I linked to above. If it works, then there is some weird code issue in your app; if it doesn't you have an environment problem on your machine. (not sure what it could be)

- pat