# Can you do autocomplete on a custom data set?

**URL:** <https://www.ruby-forum.com/t/can-you-do-autocomplete-on-a-custom-data-set/107897>\
**Category:** Rails\
**Created:** [June 27, 2007, 7:30am UTC](https://www.ruby-forum.com/t/can-you-do-autocomplete-on-a-custom-data-set/107897 "2007-06-27T07:30:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![revanche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ac91a4/32.png) [@revanche](https://www.ruby-forum.com/u/revanche)\
**Post date:** [June 27, 2007, 7:30am UTC](https://www.ruby-forum.com/t/can-you-do-autocomplete-on-a-custom-data-set/107897/1 "2007-06-27T07:30:56Z")

</div>

I’ve been researching some of the functionality for the autocompletion  
function that comes with RoR and is built around Scriptaculous.

The only question I have is if this feature can be applied to a custom  
find request or can it only search through an entire table? I have a  
field of names, but I’d prefer users only to be able to search through  
those that also have their user\_id, meaning that they created them. I  
wouldn’t want them to be able to access other user’s records.

Is this even possible?

---

<div class="post-metadata">

**Author:** ![revanche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ac91a4/32.png) [@revanche](https://www.ruby-forum.com/u/revanche)\
**Post date:** [June 27, 2007, 9:51am UTC](https://www.ruby-forum.com/t/can-you-do-autocomplete-on-a-custom-data-set/107897/2 "2007-06-27T09:51:27Z")

</div>

On Jun 27, 2007, at 7:30 AM, Neil H. wrote:

> I’ve been researching some of the functionality for the autocompletion  
> function that comes with RoR and is built around Scriptaculous.
> 
> The only question I have is if this feature can be applied to a custom  
> find request or can it only search through an entire table?

Taking the example from the Agile, the contract for

\<%= text\_field\_with\_auto\_complete :user, :language %\>

is that the controller responds to

auto\_complete\_for\_user\_language

and returns a UL whose LIs are the suggested completions. In the  
action you can do whatever you want get the list of completions. The  
class method auto\_complete\_for is just a generator, it generates a  
method with that name and some default code.

There are even more flexible solutions, but I guess that’s enough for  
what you needed.

– fxn
