# Text\_field\_with\_auto\_complete

**URL:** <https://www.ruby-forum.com/t/text-field-with-auto-complete/171888>\
**Category:** Rails\
**Created:** [July 10, 2009, 9:34pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete/171888 "2009-07-10T21:34:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 10, 2009, 9:34pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete/171888/1 "2009-07-10T21:34:14Z")

</div>

I need to pass a parameter in my text\_field\_with\_auto\_complete and am  
struggling to discover how to do this. I have something like this:

\<%= text\_field\_with\_auto\_complete ‘user’, ‘username’, {}, {:with =\>  
“‘post=’@company\_title.id”} %\>

but because it is in a partial that pops as a result from a  
remote\_function\_tag, I am having trouble seeing the html to know if this  
is even working. In any event, it is not giving me back what I want.

Is there a way to pass parameters to the auto\_complete\_for method?

Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 10, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete/171888/2 "2009-07-10T21:45:17Z")

</div>

Hi Shandy,

On Fri, 2009-07-10 at 21:34 +0200, Shandy N. wrote:

> I need to pass a parameter in my text\_field\_with\_auto\_complete

What’s the parameter supposed to do? What are you trying to accomplish?

Bill

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 10, 2009, 10:08pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete/171888/3 "2009-07-10T22:08:42Z")

</div>

bill walton wrote:

> Hi Shandy,
> 
> On Fri, 2009-07-10 at 21:34 +0200, Shandy N. wrote:
> 
> > I need to pass a parameter in my text\_field\_with\_auto\_complete
> 
> What’s the parameter supposed to do? What are you trying to accomplish?
> 
> Bill

Well, I have an auto\_complete to get users names, and in other forms it  
works great. This auto\_complete, however, it first asks the user to  
select an account and then pull all the users from that account, so the  
parameter that I need to pass is the id to the account to populate that  
list.

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 11, 2009, 12:14am UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete/171888/4 "2009-07-11T00:14:20Z")

</div>

On Fri, 2009-07-10 at 22:08 +0200, Shandy N. wrote:

> Well, I have an auto\_complete to get users names, and in other forms it  
> works great. This auto\_complete, however, it first asks the user to  
> select an account and then pull all the users from that account, so the  
> parameter that I need to pass is the id to the account to populate that  
> list.

Ah. Ok. It’s been a while since I used auto\_complete and haven’t  
tested this, but it should point you in the right general direction.  
First though, note that everything after the first two parameters is  
interpreted as elements of a hash. You don’t need the {} notation. The  
items that can appear in that hash are the parameters to  
ActiveRecord::Base#find. IIRC auto\_complete just passes them through to  
the find. You’re wanting to supply the :conditions. The syntax may be  
wrong but I already warned you I haven’t tested it. 😉

\<%= text\_field\_with\_auto\_complete ‘user’, ‘username’, :conditions =\>  
[“post = ?”, @company\_title.id] %\>

HTH,  
Bill
