Question: Simple question really - how do I use `text_field_with_auto_complete` inside a `form_for` block?

I've tried doing `f.text_field_with_auto_complete` but that gives an error, and just using `text_field_with_auto_complete` by itself doesn't seem to do anything.

Am I missing something here?

Answer: 
If your intent is to set a id field, you must:

1. render the results in LI items, each li having it DOM id set up to the id of the returned record, like this:

```
<UL>
       <LI ID="1">Item 1</LI>
       < LI ID="2">Item 2< /LI>
</UL>

```
2. Your text field would be something like:

```
<%= text_field_with_auto_complete :model, :method, {}, :after_update_element => ‘getSelectionId’ % >

```
3. and a javascript method called getSelectionId like this

```
function getSelectionId(text, li) {

alert (li.id);

}

```

note that you can do anything via javascript since you have the text and the li element available.

Another option is [this plugin](http://agilewebdevelopment.com/plugins/model_auto_completer)
I had this problem too, but the solution I used might not apply to you.

Since the object I was querying in the autocomplete belonged to a different model, I used a fields\_for like this, which solved the autocomplete problem.

```
<% fields_for :model, @formobject.model do %>
<p>
<%= text_field_with_auto_complete :object, :field, :skip_style => true %>
</p>
<% end %>

```

Good luck!