Topic: Help with ruby auto_complete text field with through association

I am having trouble getting the rails auto_complete plugin to work with my application because I can't seem to find any tutorials online that explain how to use the plugin with through associations.

I am developing an application where have I have a database of Ingredients, and another database of Recipes. As far as the models go:

    * Ingredients have many recipes through IngredientAmount
    * Each Ingredient has a name
    * Recipes have many ingredients through IngredientAmount
    * IngredientAmount belongs to Ingredient, and belongs to Recipe

The feature I want is that when a user is making a new Recipe, when he starts typing in the name of an ingredient, I want the field to auto_complete the request by searching the database of Ingredients by their name field. Most of the tutorials online specify that you have to add the line

auto_complete_for :<model>, :<field>

And, in the view, to put:

<%= text_field_with_auto_complete :<model>, :<field>, {}, {:method => :get} %>

My problem is that I don't know
   1. Where to put the 'auto_complete_for' declaration, in the recipe controller?
   2. What should be the parameters for the text_filed_with_auto_complete model and field?
   3. What should be the parameters for the auto_complete declaration?
   4. What specific changes to routes.rb do I need?

Any help would be really appreciated, thanks in advance,
Swaraj

Last edited by swarajban (2010-11-16 02:58:39)