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 %> <fieldset> <dl> <dd><label for="q">Search Users:</label> <%= text_field_tag "searchdata", params[:searchdata] %> <input id="submit" type="submit" value="Search" /></dd> </dl> </fieldset> <% 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
try something like: my_params = {} my_params.merge( :city => params[:city]) A --~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
First, it looks to me like you''re attempting to do exactly what Ryan Bates shows in episode #37 of 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 Cunnigham <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 %> > <fieldset> > <dl> > <dd><label for="q">Search Users:</label> <%= text_field_tag > "searchdata", params[:searchdata] %> > <input id="submit" type="submit" value="Search" /></dd> > </dl> > </fieldset> > > <% 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 viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robert Walker wrote:> First, it looks to me like you''re attempting to do exactly what Ryan > Bates shows in episode #37 of 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 Cunnigham <rails-mailing-l...@andreas-s.net>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: <td align=''left''> 8: 9: <% form_tag user_path, method => ''get'' do %> 10: <p> 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? -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- form_tag and form_for cause #protect_from_forgery errors
- Using Jquery plugin "tokenInput" with rails
- How to Pass Jquery selected dropdown values and radio button values to controller
- form_tag broken in Rails 1.2 RC2 or is it me?
- domain stripping searcing for ages