# Auto\_complete on steroids

**URL:** <https://www.ruby-forum.com/t/auto-complete-on-steroids/73383>\
**Category:** Rails\
**Created:** [February 26, 2006, 5:47am UTC](https://www.ruby-forum.com/t/auto-complete-on-steroids/73383 "2006-02-26T05:47:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 26, 2006, 5:47am UTC](https://www.ruby-forum.com/t/auto-complete-on-steroids/73383/1 "2006-02-26T05:47:34Z")

</div>

I am trying to get more out of auto\_complete than it apparently was  
designed to deliver.

My problems seem to be two fold.

1 - I use aggregations on  
names… :first\_name, :middle\_initial, :last\_name and then aggregate  
them using a composed\_of :wholename thing

auto\_complete\_for seems to be wired to only use table columns directly  
and gags on the aggregate form.

2 - foreign table columns - auto\_complete\_for seems to be unusable for  
obtaining matching values from a column in another table but I haven’t  
fully explored this since I was trying to get the aggregation per above  
and finally stayed within table and found that aggregations didn’t work  
period and when I checked out the api, I sort of knew why.

So I ask…is there an auto\_complete plugin/gem that I can’t seem to  
find that is like auto\_complete on steroids?

Thanks

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 26, 2006, 6:14am UTC](https://www.ruby-forum.com/t/auto-complete-on-steroids/73383/2 "2006-02-26T06:14:45Z")

</div>

Hi Craig,  
I don’t know of any ‘auto\_complete on steroids’ but you can do alot more  
than the defaults if you write your own sql.  
If you take a look at Amy Hoy’s post of auto-complete she shows how to  
do  
this in the ‘roll your own’ section.

[http://www.slash7.com/articles/2005/08/13/ajaxariffic-autocomplete-with-scriptaculous](http://www.slash7.com/articles/2005/08/13/ajaxariffic-autocomplete-with-scriptaculous)

If you do that you should be able to use CONCAT in your sql statement to  
concat a few columns together. After that you’d probably want to get rid  
of the white space from your query because after the concat, you won’t  
have any white space between firstname,middle and last. (ie.  
EricAGoodwin  
)  
Check out the example below.

SELECT \* FROM users WHERE CONCAT(firstname,middlename,lastname) =  
#{params[:q].gsub(/\s/,‘’)};

You should be able to write your own sql for the foreign tables columns  
as  
well.

Cheers,  
Eric G.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 26, 2006, 6:23am UTC](https://www.ruby-forum.com/t/auto-complete-on-steroids/73383/3 "2006-02-26T06:23:46Z")

</div>

On Sun, 2006-02-26 at 05:10 +0000, Eric G. wrote:

> of the white space from your query because after the concat, you won’t  
> have any white space between firstname,middle and last. (ie. EricAGoodwin  
> )  
> Check out the example below.
> 
> SELECT \* FROM users WHERE CONCAT(firstname,middlename,lastname) =  
> #{params[:q].gsub(/\s/,’’)};
> 
> You should be able to write your own sql for the foreign tables columns as  
> well.

* * *

yep - that looks like what I want to do.

OK - makes for some excitement on an otherwise dull Saturday night.

😉

Thanks

Craig
