# Database queries using autocomplete

**URL:** <https://www.ruby-forum.com/t/database-queries-using-autocomplete/129565>\
**Category:** Rails\
**Created:** [February 19, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/database-queries-using-autocomplete/129565 "2008-02-19T18:59:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkkkkk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c4cdca/32.png) [@kkkkkk](https://www.ruby-forum.com/u/kkkkkk)\
**Post date:** [February 19, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/database-queries-using-autocomplete/129565/1 "2008-02-19T18:59:55Z")

</div>

Hello All,  
I am new to Rails and am unable to figure out how to do multiple table  
queries to a database using autocomplete  
forms.

I have :  
Author habtm Books through Works || Book has\_many Chapters ||  
Chapter has\_many Sections  
And a table unrelated to these directly called Keywords.

How can I create a page where I provide autocomplete boxes for each of  
these so that a user can choose for a  
particular keyword/s, author/s and book/s using Boolean logic? (one  
view with multiple table search boxes)

ex: keyword ‘civilization’ AND/OR/NOT author ‘Jay’ AND/OR/NOT book  
‘xyz’

I was able to create multiple choice autocomplete boxes using the  
following code:

\<%=javascript\_include\_tag :defaults%\>

#### Search for Authors
 \<% form\_for :author, :url =\>{:action =\> "show", :controller =\> "author"} do |form|%\> \<%= text\_field\_with\_auto\_complete :author, :name, {},{:tokens =\> [',', '\n']}%\> \<%=submit\_tag "Go", :id =\> @author%\> \<%end%\>

But once I added the tokens options, my show action does not work for  
more than one choice (it works fine  
when only one author was chosen).

My show.rhtml looks like this:

\<% for column in Author.content\_columns %\>  
\<%= column.name %\>: \<%=h @author.send(column.name) %\>  
\<% end %\>

Can someone please help me out?

Thanks,  
KK
