Parameterizing auto-completion?


#1

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


#2

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

#3

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 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.