# Problem getting started with auto\_complete

**URL:** <https://www.ruby-forum.com/t/problem-getting-started-with-auto-complete/178073>\
**Category:** Rails\
**Created:** [October 28, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/problem-getting-started-with-auto-complete/178073 "2009-10-28T20:10:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gee-off](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@Gee-off](https://www.ruby-forum.com/u/Gee-off)\
**Post date:** [October 28, 2009, 8:10pm UTC](https://www.ruby-forum.com/t/problem-getting-started-with-auto-complete/178073/1 "2009-10-28T20:10:37Z")

</div>

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"></

```

div\>  
\<%= 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

---

<div class="post-metadata">

**Author:** ![Gee-off](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@Gee-off](https://www.ruby-forum.com/u/Gee-off)\
**Post date:** [October 28, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/problem-getting-started-with-auto-complete/178073/2 "2009-10-28T20:25:50Z")

</div>

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

Here is one plugin that can be used

> **[GitHub - rails/auto\_complete: NOTICE: official repository moved to...](https://github.com/rails/auto_complete)**
>
> NOTICE: official repository moved to https://github.com/david-kerins/auto\_complete - GitHub - rails/auto\_complete: NOTICE: official repository moved to https://github.com/david-kerins/auto\_complete

---

<div class="post-metadata">

**Author:** ![Gee-off](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@Gee-off](https://www.ruby-forum.com/u/Gee-off)\
**Post date:** [October 28, 2009, 8:43pm UTC](https://www.ruby-forum.com/t/problem-getting-started-with-auto-complete/178073/3 "2009-10-28T20:43:58Z")

</div>

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](http://patshaughnessy.net/2009/10/1/auto_complete-scaffolding)

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

---

<div class="post-metadata">

**Author:** ![Gee-off](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@Gee-off](https://www.ruby-forum.com/u/Gee-off)\
**Post date:** [October 29, 2009, 4:49pm UTC](https://www.ruby-forum.com/t/problem-getting-started-with-auto-complete/178073/4 "2009-10-29T16:49:09Z")

</div>

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://  
[pragprog.com/titles/rails3/source\_code](http://pragprog.com/titles/rails3/source_code)).

There is no mention of this issue in the errata ([http://pragprog.com/](http://pragprog.com/)  
titles/rails3/errata).

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

---

<div class="post-metadata">

**Author:** ![Gee-off](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@Gee-off](https://www.ruby-forum.com/u/Gee-off)\
**Post date:** [October 29, 2009, 5:23pm UTC](https://www.ruby-forum.com/t/problem-getting-started-with-auto-complete/178073/5 "2009-10-29T17:23:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Gee-off](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@Gee-off](https://www.ruby-forum.com/u/Gee-off)\
**Post date:** [October 30, 2009, 2:40pm UTC](https://www.ruby-forum.com/t/problem-getting-started-with-auto-complete/178073/6 "2009-10-30T14:40:25Z")

</div>

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: removed\_email\_address@domain.invalid

… 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
