# Text field with autocomplete

**URL:** <https://www.ruby-forum.com/t/text-field-with-autocomplete/181212>\
**Category:** Rails\
**Created:** [January 7, 2010, 1:02pm UTC](https://www.ruby-forum.com/t/text-field-with-autocomplete/181212 "2010-01-07T13:02:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![golf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/90db22/32.png) [@golf](https://www.ruby-forum.com/u/golf)\
**Post date:** [January 7, 2010, 1:02pm UTC](https://www.ruby-forum.com/t/text-field-with-autocomplete/181212/1 "2010-01-07T13:02:04Z")

</div>

Hey everybody,

I am using text field with autocomplete in my posts new action. That  
works great.  
Response from autocompleter in firebug:  
POST [http://localhost:3001/posts/auto\_complete\_for\_tag\_name](http://localhost:3001/posts/auto_complete_for_tag_name) 200 OK 68ms

but if I use the same in edit action it fails and I got this error.  
POST [http://localhost:3001/posts/781/auto\_complete\_for\_tag\_name](http://localhost:3001/posts/781/auto_complete_for_tag_name) 404 Not  
Found 81ms

\*\*\* POSTS controller: \*\*\*  
def auto\_complete\_for\_tag\_name  
@tag = Tag.find(:all, :conditions =\> [“name LIKE  
?”,#{params[:tag][:name]}%"])  
render :inline =\> “\<%= auto\_complete\_result(@tag, ‘name’) %\>”  
end

\*\*\* posts NEW and EDIT view \*\*\*

 \<% form\_remote\_tag( :url =\> {:controller =\> :tags}, :html =\> {:id =\> 'tag\_form'}) do %\> Name: \<%= text\_field\_with\_auto\_complete :tag, :name, {:min\_chars =\> 2, :class =\> "text"} %\> \<%= submit\_tag 'Add' %\> \<% end %\>

Thank for your help.

Cheer Pete

---

<div class="post-metadata">

**Author:** ![golf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/90db22/32.png) [@golf](https://www.ruby-forum.com/u/golf)\
**Post date:** [January 7, 2010, 7:27pm UTC](https://www.ruby-forum.com/t/text-field-with-autocomplete/181212/2 "2010-01-07T19:27:16Z")

</div>

Maybe try form\_for instead of form\_remote\_tag?

I wrote a gem that creates some scaffolding code customized for the  
auto complete that might help you get a form working in your app  
quickly; see:  
[http://patshaughnessy.net/2009/10/1/auto\_complete-scaffolding](http://patshaughnessy.net/2009/10/1/auto_complete-scaffolding)  
Later you could adapt the scaffolding code to do what you really need.

- pat  
[http://patshaughnessy.net](http://patshaughnessy.net)
