I''ve been struggling with this function for most of the morning, but something just doesn''t seem right in my logic with respect to efficiency. I have a basic view that is submitting information on three variables directly to this function. The information is accessible simply through params[:filtera1], params[:filtera2] and params[:filtera1]. I''m trying to build a find that will check the filter_a column in my database table (places) and list the record if filter_a matches any one of the three parameters just passed to it. The difficulty comes from two areas 1. I have not perfected the right syntax for using OR in conditions and most of the documentation I have found is not too helpful. 2. There is the chance that some of the information passed through may be equal to nil - and finds like to break at that point. Any help would be appreciated. PS: If anyone is looking for a small job of helping me figure out these basic concepts in exchange for some weekly drinking money, I''d be more than happy to consider such an arrangement. Everyone''s time is valuable, afterall. -- 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 -~----------~----~----~----~------~----~------~--~---
Why not post your code so we can take a look at the logic? Regards, Dave _______________________________ Information and Educational Technology Kwantlen University College - 604-599-2120 Robert Scott <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> Sent by: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 05-07-2007 12:50 PM Please respond to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org cc Subject [Rails] Using conditions appropriately I''ve been struggling with this function for most of the morning, but something just doesn''t seem right in my logic with respect to efficiency. I have a basic view that is submitting information on three variables directly to this function. The information is accessible simply through params[:filtera1], params[:filtera2] and params[:filtera1]. I''m trying to build a find that will check the filter_a column in my database table (places) and list the record if filter_a matches any one of the three parameters just passed to it. The difficulty comes from two areas 1. I have not perfected the right syntax for using OR in conditions and most of the documentation I have found is not too helpful. 2. There is the chance that some of the information passed through may be equal to nil - and finds like to break at that point. Any help would be appreciated. PS: If anyone is looking for a small job of helping me figure out these basic concepts in exchange for some weekly drinking money, I''d be more than happy to consider such an arrangement. Everyone''s time is valuable, afterall. -- 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 -~----------~----~----~----~------~----~------~--~---
Table: Places name - location name filtera - integer corresponding to a particular area (1, 2 or 3) View: Allows user to select what area they are located in. Checkboxes and Ajax were utilized to make the results table dynamically update as they make selections, and also to enable users to make multiple selections. From the basic tests, this works fine and passes the data along to the results function. <form name="interest" id="interest"> <input name="filtera1" type="checkbox" id="filtera1" value="1" /> <input name="filtera2" type="checkbox" id="filtera2" value="2" /> <input name="filtera3" type="checkbox" id="filtera3" value="3" /> </form> <%= observe_form ''interest'', :frequency => 0.25, :update => ''search_target'', :url => { :controller => ''stores'', :action => ''results'' } %> <div id="search_target"> </div> Controller: def results @results = Place.find(:all, :conditions => { :filter_a => params[:filtera1] OR :filter_a => params[:filtera2] OR :filter_a => params[:filtera3]}) end -- 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 -~----------~----~----~----~------~----~------~--~---
On 7/5/07, Robert Scott <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Table: Places > name - location name > filtera - integer corresponding to a particular area (1, 2 or 3) > > > View: > Allows user to select what area they are located in. Checkboxes and Ajax > were utilized to make the results table dynamically update as they make > selections, and also to enable users to make multiple selections. From > the basic tests, this works fine and passes the data along to the > results function. > > <form name="interest" id="interest"> > <input name="filtera1" type="checkbox" id="filtera1" value="1" /> > <input name="filtera2" type="checkbox" id="filtera2" value="2" /> > <input name="filtera3" type="checkbox" id="filtera3" value="3" /> > </form> > <%= observe_form ''interest'', :frequency => 0.25, > :update => ''search_target'', > :url => { :controller => ''stores'', :action => ''results'' } > %> > > <div id="search_target"> > > </div> > > Controller: > > def results > > @results = Place.find(:all, :conditions => { :filter_a => > params[:filtera1] OR :filter_a => params[:filtera2] OR :filter_a => > params[:filtera3]}) > > > enduse something like the following: def results conditions = "true" par = [] unless params[:filtera1].blank? conditions << " and filtera = ?" par << params[:filtera1] end unless params[:filtera2].blank? conditions << " or filtera = ?" par << params[:filtera2] end unless params[:filtera3].blank? conditions << " or filtera = ?" par << params[:filtera3] end @results = Place.find(:all, :conditions => [conditions] + par) end or use a plugin such as criteria_query (http://www.muermann.org/ruby/criteria_query/) Mike --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---