# Text\_field\_with\_auto\_complete

**URL:** <https://www.ruby-forum.com/t/text-field-with-auto-complete/138043>\
**Category:** Rails\
**Created:** [May 19, 2008, 7:13pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete/138043 "2008-05-19T19:13:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [May 19, 2008, 7:13pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete/138043/1 "2008-05-19T19:13:21Z")

</div>

I am using the auto\_complete functionality

\<%= text\_field\_with\_auto\_complete :category, :name … %\>

after the user select an item , I need to get the ID of the selected  
item (category[:id]), is there any way to do it ? so I could give a  
value to a hidden field in my form, using the :after\_update  
OR  
should I get it later with a Category.find\_by\_name (which will add  
another DB request…)

thanks for your suggestions

kad

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [May 19, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete/138043/2 "2008-05-19T21:54:25Z")

</div>

On Mon, May 19, 2008 at 7:13 PM, Kad K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am using the auto\_complete functionality
> 
> \<%= text\_field\_with\_auto\_complete :category, :name … %\>
> 
> after the user select an item , I need to get the ID of the selected  
> item (category[:id]), is there any way to do it ? so I could give a  
> value to a hidden field in my form, using the :after\_update  
> OR  
> should I get it later with a Category.find\_by\_name (which will add  
> another DB request…)

Have a look at model\_auto\_completer:

[http://agilewebdevelopment.com/plugins/model\_auto\_completer](http://agilewebdevelopment.com/plugins/model_auto_completer)
