text_field_with_auto_complete help


I am trying to understand how auto_complete works. The docs don't
tell me what each parameter is, they all assume I know what they are.
All I want to do is have a form that contains news stories that you
can tag, with the tag suggestions coming from the tags table.

In one example ( http://agilewebdevelopment.com/plugins/auto_complete
) he says:

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

# View
<%= text_field_with_auto_complete :post, title %>

Here, you have the controller class, Blog, and post, and title. What
are these? Is post the name of an existing object? Is title the
field of a class?

In another example ( http://trix.pl/blog/ruby-on-rails/auto-complete-for-rails-2-0-tutorial
) , he says:

class DomainsController < ApplicationController

auto_complete_for :domain, :name

here, the controller name is the same as the first param of the

It's all so confusing.

Anyway, can someone break down what the parameters mean?

My situation specifically is, I have a stories table, a storytags
table and a tags table. I want the user to be able to add a tag to a
story on a form, using autocomplete for a field in a table that's not
the same as the primary table (stories).

If anyone can give me a push in the right direction, I'd appreciate



Extract from APRESS book...pg 218

Extract from APRESS book...pg 218

Thanks for the reply. What do you do if the source of the
auto_complete is not a field in the model? All of the examples I have
found assume this.

Listing 7-16.
Adding the auto_complete_for helper in app/controllers/

class EventsController < ApplicationController
before_filter :authenticate, :except => [:index, :show]
auto_complete_for :event, :location

This piece of code will tell the controller to return a list of the
existing locations in the

Again, yes, assuming locations is not a has_many table, or, eve worse,
a has_and_blongs_to_many. Any ideas in these cases?

Thanks again,