Newbie: Searcing database via user form input?

Dale Cunnigham
2008-05-28T12:24:40Z

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] %>
    <input id="submit" type="submit"
value="Search" />



<% 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?
--
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org