Newbie: Searcing database via user form input?

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?

try something like:

my_params = {}

my_params.merge( :city => params[:city])

A

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

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. [email protected]

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

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. [email protected]

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?