I''am trying to create a search sytem with two arguments When one argument is choosen it needs find all the objects with that argument and when two choosen it needs to find all objects with both arguments. In my view <% form_tag :action => ''tuinen'', :method => ''get'' do %> <%= options = [["Selecteer een provincie", ""]] + User::PROVINCES select("search", nil, options) %> <%= select ''heading'', nil, Heading.find(:all).collect {|p| [ p.name, p.id ] }, { :prompt => "selecteer een rubriek"} %> <%= submit_tag "Zoek mijn tuin"%><br><br> <% end %> the problem is into my controller i can''t find no way to seperate the aruments i tried several methods but nothing works my basic method is like this if @params[:search] @gardens = Garden.find(:all, :conditions => {:provincie => @params[:search], :heading_id => @params[:heading], :destroyed => 0}) -- 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 -~----------~----~----~----~------~----~------~--~---
I think you might want something like @gardens = Garden.find(:all, :conditions => ["provincie = ? and heading_id = ? and destroyed = 0", @params[:search], @params[:heading] ] This variant of :conditions creates a SQL fragment for a where clause that replaces the ?''s in order with the values provided after the first comma (and has the added benefit of preventing SQL injection). Is the what you were looking for? Tom On Dec 20, 11:53 am, GA Gorter <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''am trying to create a search sytem with two arguments > When one argument is choosen it needs find all the objects with that > argument > and when two choosen it needs to find all objects with both arguments. > > In my view > > <% form_tag :action => ''tuinen'', :method => ''get'' do %> > <%= options = [["Selecteer een provincie", ""]] + User::PROVINCES > select("search", nil, options) > %> > <%= select ''heading'', nil, Heading.find(:all).collect {|p| [ p.name, > p.id ] }, { :prompt => "selecteer een rubriek"} %> > <%= submit_tag "Zoek mijn tuin"%><br><br> > <% end %> > > the problem is into my controller i can''t find no way to seperate the > aruments > i tried several methods but nothing works > > my basic method is like this > > if @params[:search] > @gardens = Garden.find(:all, :conditions => {:provincie => > @params[:search], :heading_id => @params[:heading], :destroyed => 0}) > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Whoops -- I missed a closing ) after the last ] :-) On Dec 20, 7:12 pm, tharrison <tom.harrison...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I think you might want something like > > @gardens = Garden.find(:all, :conditions => ["provincie = ? and > heading_id = ? and destroyed = 0", @params[:search], > @params[:heading] ] > > This variant of :conditions creates a SQL fragment for a where clause > that replaces the ?''s in order with the values provided after the > first comma (and has the added benefit of preventing SQL injection). > > Is the what you were looking for? > > Tom > > On Dec 20, 11:53 am, GA Gorter <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > I''am trying to create a search sytem with two arguments > > When one argument is choosen it needs find all the objects with that > > argument > > and when two choosen it needs to find all objects with both arguments. > > > In my view > > > <% form_tag :action => ''tuinen'', :method => ''get'' do %> > > <%= options = [["Selecteer een provincie", ""]] + User::PROVINCES > > select("search", nil, options) > > %> > > <%= select ''heading'', nil, Heading.find(:all).collect {|p| [ p.name, > > p.id ] }, { :prompt => "selecteer een rubriek"} %> > > <%= submit_tag "Zoek mijn tuin"%><br><br> > > <% end %> > > > the problem is into my controller i can''t find no way to seperate the > > aruments > > i tried several methods but nothing works > > > my basic method is like this > > > if @params[:search] > > @gardens = Garden.find(:all, :conditions => {:provincie => > > @params[:search], :heading_id => @params[:heading], :destroyed => 0}) > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It does not what i want I want a system when i choose only a province i get all gardens in that specific province And when i set the heading i get all gardens with that specific heading And when i set them both i get all gardens in that province and that heading In this way only when i set both i get the right results even like the system i had in the post above. -- 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 -~----------~----~----~----~------~----~------~--~---