views:

444

answers:

2

I'm trying to make an autocomplete textfield for my Rails app, following the Agile Web Development with Rails, 3rd Ed example. But if I simply paste their demo code in:

<%= stylesheet_link_tag 'autocomplete' %>
<h1>Editing user</h1>

<% form_tag :action => 'update', :id => @user do %>
  <%= error_messages_for 'user' %>

  <p>Username<br/>
  <%= @user.username  %></p>

  <%# codecite autocomplete %>

  <p><label for="user_favorite_language">Favorite language</label><br/>
  <%= text_field 'user', 'favorite_language'  %></p>   
  <div class="auto_complete" 
       id="user_favorite_language_auto_complete"></div>
  <%= auto_complete_field :user_favorite_language,   
        :url=>{:action=>'autocomplete_favorite_language'}, :tokens => ',' %>

  <%# codecite autocomplete %>
  <%= submit_tag 'Edit' %>
<% end %>


<%= link_to 'Show', :action => 'show', :id => @user %> |
<%= link_to 'Back', :action => 'list' %>

I will get an error saying:

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

Is there anything else that they should have told me to get this to work? http://media.pragprog.com/titles/rails3/code/pragforms/app/views/user/autocomplete_demo.rhtml

EDIT: This section was under Scriptculous so I thought just installing that library would do.

+2  A: 

That's probably an outdated snippet, or another auto-complete plugin.

The official auto-complete plugin for Rails resides at http://github.com/rails/auto_complete/

You can install the official plugin like this:

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

UPDATE:

Apparently

script/plugin install auto_complete

works just as well.

Can Berk Güder
Why do I get this? undefined method `auto_complete_for' for PrivateMessagesController:Class
alamodey
You shouldn't get such an error if the plugin is installed properly and if PrivateMessagesController is a descendant of ActionController.
Can Berk Güder
A: 

Did you install the autocomplete plugin? What version of Rails? This link might be of help to you for Rails 2.

tvanfosson