Hi, I have loops that loop through params values from a form and retrieve records from the database and then plot a graph. BUT: If the user selects a check box in the form the loop is 3 nested loops instead of 5. ALSO: There is another checkbox that causes 5 loops (same as first case) but does an extra calculation on the records in the inner loop. My point is these 3 cases are similar: how should I deal with them? At the moment the loops all occur in the controller - should I move them to a model - a model for each graph type? Or should I have one set of loops and do some clever conditional flow to get all three cases out of it? Any ideas on the best practice when doing loops? Chris. -- 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 on earth do you need 5 nested loops? What are you trying to do? -- 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 -~----------~----~----~----~------~----~------~--~---
Mick Sharpe wrote:> Why on earth do you need 5 nested loops? What are you trying to do?Well, the query to make up the graph requires 5 different parameters - it is to graph measurements made on a machine: there are 10 machines - so the user selects one (or multiple) there are 8 different measurement types there are 2 types of machine output there are 3 types of something else they must select the date range and a check box whether they want the results as % of a reference value or not. I then, for each machine, loop through what is required and get the results from the database on the inner loop. I then loop through it all to send results to gnuplot. It starts to become a head ache. Questions from my first post still stand. Chris. -- 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 -~----------~----~----~----~------~----~------~--~---
You might be able to dry up your code using some code that I knocked up to iterate over a number of arrays using nested looping: http://www.ruby-forum.com/topic/95539 -- 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 -~----------~----~----~----~------~----~------~--~---
Mick Sharpe wrote:> You might be able to dry up your code using some code that I knocked up > to iterate over a number of arrays using nested looping: > > http://www.ruby-forum.com/topic/95539Great Mick, that''s a slick bit of code - could be just what I need. -- 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 -~----------~----~----~----~------~----~------~--~---
Chris Finch wrote:> Mick Sharpe wrote: >> You might be able to dry up your code using some code that I knocked up >> to iterate over a number of arrays using nested looping: >> >> http://www.ruby-forum.com/topic/95539 > > Great Mick, that''s a slick bit of code - could be just what I need.Darn, I have to do some processing between loops - i.e. not just on the inner loop - don''t think I can use it:-( C -- 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 -~----------~----~----~----~------~----~------~--~---