# Newbie: Searcing database via user form input?

**URL:** <https://www.ruby-forum.com/t/newbie-searcing-database-via-user-form-input/138862>\
**Category:** Rails\
**Created:** [May 28, 2008, 2:24pm UTC](https://www.ruby-forum.com/t/newbie-searcing-database-via-user-form-input/138862 "2008-05-28T14:24:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![oshuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ea5d25/32.png) [@oshuma](https://www.ruby-forum.com/u/oshuma)\
**Post date:** [May 28, 2008, 2:24pm UTC](https://www.ruby-forum.com/t/newbie-searcing-database-via-user-form-input/138862/1 "2008-05-28T14:24:40Z")

</div>

Does anyone have a tutorial on adding new parameters to the paramaters  
list and then creating find conditions around them?

I’m wondering how I can get my index page to list only the items where  
some of the the databases fields match user form input. index.html.erb  
would be calling itself with a new parameter :searchdata

So far the index.html.erb has…

\<% form\_tag({ :action =\> “index”, :controller =\> “users” }, :method =\>  
“index”) do %\>

Search Users: \<%= text\_field\_tag "searchdata", params[:searchdata] %\> 

\<% end %\>

and the users\_controller index contains

def index  
@users = User.find(:all, :conditions =\> “Surname LIKE ?”,  
params[:searchdata])

```
respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @users }
end

```

end

So this is broken. Does anyone have a tutorial on adding new parameters  
to the paramaters list and then creating find conditions around them?

---

<div class="post-metadata">

**Author:** ![oshuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ea5d25/32.png) [@oshuma](https://www.ruby-forum.com/u/oshuma)\
**Post date:** [May 28, 2008, 6:44pm UTC](https://www.ruby-forum.com/t/newbie-searcing-database-via-user-form-input/138862/2 "2008-05-28T18:44:27Z")

</div>

try something like:

my\_params = {}

my\_params.merge( :city =\> params[:city])

A

---

<div class="post-metadata">

**Author:** ![oshuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ea5d25/32.png) [@oshuma](https://www.ruby-forum.com/u/oshuma)\
**Post date:** [May 29, 2008, 1:14am UTC](https://www.ruby-forum.com/t/newbie-searcing-database-via-user-form-input/138862/3 "2008-05-29T01:14:45Z")

</div>

First, it looks to me like you’re attempting to do exactly what Ryan  
Bates shows in episode #37 of Railscasts:

> **[\#37 Simple Search Form - RailsCasts](http://railscasts.com/episodes/37-simple-search-form)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Second: What’s this?

> \<% form\_tag({ :action =\> “index”, :controller =\> “users” }, :method =\>  
> “index”) do %\>  
> There is no “index” method in HTTP. This should be one of :get  
> or :post in the context of an HTML form.

On May 28, 8:24 am, Dale C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![oshuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ea5d25/32.png) [@oshuma](https://www.ruby-forum.com/u/oshuma)\
**Post date:** [May 29, 2008, 5:13pm UTC](https://www.ruby-forum.com/t/newbie-searcing-database-via-user-form-input/138862/4 "2008-05-29T17:13:18Z")

</div>

Robert W. wrote:

> First, it looks to me like you’re attempting to do exactly what Ryan  
> Bates shows in episode #37 of Railscasts:
> 
> [#37 Simple Search Form - RailsCasts](http://railscasts.com/episodes/37)
> 
> Second: What’s this?
> 
> > \<% form\_tag({ :action =\> “index”, :controller =\> “users” }, :method =\>  
> > “index”) do %\>  
> > There is no “index” method in HTTP. This should be one of :get  
> > or :post in the context of an HTML form.
> 
> On May 28, 8:24ï¿½am, Dale C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Ok so I followed the instructions in that rails cast (thanks for that,  
really great resource) but I’m now getting a routing/path problem…

ActionController::RoutingError in Users#index

Showing users/index.html.erb where line #9 raised:

user\_url failed to generate from {:action=\>“show”, :controller=\>“users”}

- you may have ambiguous routes, or you may need to supply additional  
parameters for this route. content\_url has the following required  
parameters: [“users”, :id] - are they all satisfied?

Extracted source (around line #9):

6:  
7:   
8:  
9: \<% form\_tag user\_path, method =\> ‘get’ do %\>  
10:

11: \<%= text\_field\_tag :search, params[:search] %\>  
12: \<%= submit\_tag “Search Users”, :name =\> nil %\>

so it looks like it cant render user\_path to an appropriate url.

My routes.rb file does contain

ActionController::Routing::Routes.draw do |map|  
map.resources :users

So I thought user\_path would be generated by that line automatically,  
and then the page gets routed to the ‘index’ action automatically no?
