# Scriptaculous autocompletion LIMIT and ajax vs. local

**URL:** <https://www.ruby-forum.com/t/scriptaculous-autocompletion-limit-and-ajax-vs-local/62271>\
**Category:** Rails\
**Created:** [June 2, 2006, 2:37am UTC](https://www.ruby-forum.com/t/scriptaculous-autocompletion-limit-and-ajax-vs-local/62271 "2006-06-02T02:37:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@alon](https://www.ruby-forum.com/u/alon)\
**Post date:** [June 2, 2006, 2:37am UTC](https://www.ruby-forum.com/t/scriptaculous-autocompletion-limit-and-ajax-vs-local/62271/1 "2006-06-02T02:37:24Z")

</div>

Hi,

I am using scriptaculous ajax autocompletion (not local autocompletion).  
I have 2 questions:

1 - The database query being sent to the server always has LIMIT 10. I  
don’t want to have a limit, but I just can’t for the life of me find  
where this limit is set in the code. I did see “choices: 10” in  
controls.js but that’s for autocompleter.Local, which I don’t use, and  
changing it has no effect. Also, I can’t see setting the limit as being  
a part of the options array. How do I remove it?

2 - I am debating whether to use the ajax or local autocompletion. The  
autocomplete values are to be retrieved from a table with about 2000  
values, that don’t change frequently at all. On one hand I don’t want to  
use ajax since it involves a lot of db queries, and on the other hand,  
with local, I don’t know if injecting about 2000 values (avg 10 bytes  
each) into the page is a good idea (or is it not a big deal?). Any  
advice?

Feedback is very appreciated!  
Alon.

---

<div class="post-metadata">

**Author:** ![alon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@alon](https://www.ruby-forum.com/u/alon)\
**Post date:** [June 2, 2006, 2:53am UTC](https://www.ruby-forum.com/t/scriptaculous-autocompletion-limit-and-ajax-vs-local/62271/2 "2006-06-02T02:53:39Z")

</div>

On Fri, Jun 02, 2006 at 02:37:24AM +0200, Alon G. wrote:

> 2 - I am debating whether to use the ajax or local autocompletion. The  
> autocomplete values are to be retrieved from a table with about 2000  
> values, that don’t change frequently at all. On one hand I don’t want to  
> use ajax since it involves a lot of db queries, and on the other hand,  
> with local, I don’t know if injecting about 2000 values (avg 10 bytes  
> each) into the page is a good idea (or is it not a big deal?). Any  
> advice?

If the data don’t change during the lifetime of the page input form,  
you’re only talking about 20k … which is probably less than one of the  
image files you’re probably using elsewhere 🙂

You could decide to minimise that 20k by using some sort of unique  
pruning/compression, and expand the list when it gets to the client end,  
but that sounds like too much hard work 🙂 Just enabling compression in  
yout HTTP server will probably achieve greater savings 🙂

-jim

---

<div class="post-metadata">

**Author:** ![alon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@alon](https://www.ruby-forum.com/u/alon)\
**Post date:** [June 2, 2006, 3:06am UTC](https://www.ruby-forum.com/t/scriptaculous-autocompletion-limit-and-ajax-vs-local/62271/3 "2006-06-02T03:06:46Z")

</div>

> If the data don’t change during the lifetime of the page input form,  
> you’re only talking about 20k … which is probably less than one of the  
> image files you’re probably using elsewhere 🙂

ah, good point! puts things in perspective 🙂

thanks Jim. appreciated.

---

<div class="post-metadata">

**Author:** ![alon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@alon](https://www.ruby-forum.com/u/alon)\
**Post date:** [June 2, 2006, 3:19pm UTC](https://www.ruby-forum.com/t/scriptaculous-autocompletion-limit-and-ajax-vs-local/62271/4 "2006-06-02T15:19:55Z")

</div>

Anybody knows the answer to the LIMIT question?

---

<div class="post-metadata">

**Author:** ![alon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@alon](https://www.ruby-forum.com/u/alon)\
**Post date:** [June 2, 2006, 3:51pm UTC](https://www.ruby-forum.com/t/scriptaculous-autocompletion-limit-and-ajax-vs-local/62271/5 "2006-06-02T15:51:25Z")

</div>

On Jun 2, 2006, at 15:19, Alon G. wrote:

> Anybody knows the answer to the LIMIT question?

I guess you want:

auto\_complete\_for :post, :title, :limit =\> 15, :order =\>  
‘created\_at DESC’

For full generality the contract is you write an action with  
“auto\_complete\_for” prepended to the model and attribute names like  
this, given you want to autocomplete for :card, :back in the form:

def auto\_complete\_for\_card\_back  
@words = Word.find(  
:all,  
:conditions =\> [‘word LIKE ?’, params[:card][:back] + ‘%’],  
:limit =\> 10,  
:order =\> ‘word ASC’  
)  
render :layout =\> false  
end

and generate a list as view:

 \<% for word in @words %\> - \<%= word.word %\>
 \<% end %\> 

Does that help?

– fxn

---

<div class="post-metadata">

**Author:** ![alon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f05b48/32.png) [@alon](https://www.ruby-forum.com/u/alon)\
**Post date:** [June 2, 2006, 4:12pm UTC](https://www.ruby-forum.com/t/scriptaculous-autocompletion-limit-and-ajax-vs-local/62271/6 "2006-06-02T16:12:29Z")

</div>

Xavier N. wrote:

> Does that help?

yes! thanks a lot, exactly what I was looking for.

Alon.
