# Search in database

**URL:** <https://www.ruby-forum.com/t/search-in-database/171979>\
**Category:** Rails\
**Created:** [July 12, 2009, 9:16pm UTC](https://www.ruby-forum.com/t/search-in-database/171979 "2009-07-12T21:16:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![christian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b2d939/32.png) [@christian](https://www.ruby-forum.com/u/christian)\
**Post date:** [July 12, 2009, 9:16pm UTC](https://www.ruby-forum.com/t/search-in-database/171979/1 "2009-07-12T21:16:06Z")

</div>

Hi,

Im am really new to RoR and web and I need some basic help:

I would like to have a text\_field and a button in a view, from where I  
can type in a string, passing that string to the server side that  
iterates through my database to see if the string is within the  
database. The server side should then return if the string was found  
or not.

What I have problem with in this example is especially how the routing  
works between the client/server when just having a string variable  
that should be sent to the server without being a model. The code on  
the server side is kind of clear.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![christian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b2d939/32.png) [@christian](https://www.ruby-forum.com/u/christian)\
**Post date:** [July 13, 2009, 12:04am UTC](https://www.ruby-forum.com/t/search-in-database/171979/2 "2009-07-13T00:04:20Z")

</div>

Here is a snip of my view code

```
<% form_for(:post, :url => search_path, :html => { :method

```

=\> :get }) do |f| -%\>  
\<%= text\_field\_tag :q, params[:q], “Enter search term(s)”, :style  
=\> ‘color: #999;’ %\>  
\<%= f.submit(“Search”)%\>  
\<% end -%\>

And here is the controller:

def search  
@users = User.search params[:q]  
end

User.search is using Sphinx to search the database…
