# Parameterizing auto-completion?

**URL:** <https://www.ruby-forum.com/t/parameterizing-auto-completion/88717>\
**Category:** Rails\
**Created:** [March 13, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/parameterizing-auto-completion/88717 "2007-03-13T19:39:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [March 13, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/parameterizing-auto-completion/88717/1 "2007-03-13T19:39:19Z")

</div>

Is there a way to pass in a parameter (e.g. an ID) to the  
auto\_complete\_for… method? I have a table of answers that I’m  
serving up for auto-completion, but I only want the answers that apply  
to a given field. In my answers table, each entry has an list ID, and  
I would like to be able to to just get the answers that match the ID  
for a particular list.

I’ve overridden the auto\_complete\_for… for method to specify my  
own :conditions parameter, but so far I’m hard-coding the answer list  
ID. What I’d really like to do is, perhaps in the rhtml, specify an  
ID parameter that then somehow the auto\_complete\_for… would be able  
to access. Is there a way to do that?

Thanks,  
–Paul

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [March 13, 2007, 8:23pm UTC](https://www.ruby-forum.com/t/parameterizing-auto-completion/88717/2 "2007-03-13T20:23:25Z")

</div>

I found a solution, which I will share for the other newbies out  
there. It turns out that you can specify an :id parameter for the URL  
you are accessing for the autocompletion by doing this in your view:

\<%= text\_field\_with\_auto\_complete :answer, :answer\_text, {},  
{url=\>{:action=\>‘auto\_complete\_for\_answer\_answer\_text’, :id=\>23} }%\>

Here the :action is set to my auto\_complete\_for method, and the id is  
the ID of the list whose options I want to use for auto-completion.  
In my controller, the auto\_complete\_for\_answer\_answer\_text can access  
the ID as params[:id].

```
      --Paul
```

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [March 13, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/parameterizing-auto-completion/88717/3 "2007-03-13T21:06:41Z")

</div>

Hi

I am using Ajax.Updater and I am having a bit of a  
problem with Prototype. I am trying to use a sortable  
list (from scriptaculous) and so I want using ajax do  
some server logic.

Problem is that the list never show the correct array  
on the server side. So I looked at the javascript (you  
can see the code lower that works…)

When I look at the Sortable.serialize(‘list’); it show  
correctly list[]=1&list[]=4&list[]=3

So I would expect the ajax request to look as a get

myurl/?list[]=1&list[]=4&list[]=3  
but instead show a weird querystring

myurl/?list%5B%5D=3&\_=

So looks like when the param are serialized in the  
Ajax object itself is screwed up. I have a work around  
but wonder if someone else had the same problem… Also  
the [dev.rubyonrails.com](http://dev.rubyonrails.com) is down so I cannot post/look  
up bugs

following is my javascript code that works but I had  
to set the parameters to false and append my  
querystring to the URL to fix it…

Emmanuel

* * *

Finding fabulous fares is fun.  
Let Yahoo! FareChase search your favorite travel sites to find flight  
and hotel bargains.  
[http://farechase.yahoo.com/promo-generic-14795097](http://farechase.yahoo.com/promo-generic-14795097)
