hi, I have the following scenario within my rails code, where @manufacturers is an activerecord object with many cars @manufacturers.each do |manufacturer| manufacturer.cars.each do |car| end end with the above i''m carrying out a number of tests against the car, and if it fails I want to remove that car from the array, but I don''t want to destroy it, e.g. I don''t want to delete it from the database. Unfortunately I can''t select the cars I want from SQL so I''ve got to do it this way. Can anyone help? thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hiddenhippo wrote:> hi, > > I have the following scenario within my rails code, where > @manufacturers is an activerecord object with many cars > > > @manufacturers.each do |manufacturer| > manufacturer.cars.each do |car| > > end > end > >@manufacturers.each do |manufacturer| manufacturer.cars.map! do |car| lambda { return car if car "meets whatever conditions" } end end That will build you a new array of cars, inside the lambda block you can do all of your testing and return the car object if it meets your conditions.> with the above i''m carrying out a number of tests against the car, and > if it fails I want to remove that car from the array, but I don''t want > to destroy it, e.g. I don''t want to delete it from the database. > Unfortunately I can''t select the cars I want from SQL so I''ve got to > do it this way. > > Can anyone help? > > thanks > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Russell McConnachie wrote:> hiddenhippo wrote: >> hi, >> >> I have the following scenario within my rails code, where >> @manufacturers is an activerecord object with many cars >> >> >> @manufacturers.each do |manufacturer| >> manufacturer.cars.each do |car| >> >> end >> end >> >> > @manufacturers.each do |manufacturer| > manufacturer.cars.map! do |car| > lambda { > return car if car "meets whatever conditions" > } > end > endI forgot the .call on the end of the lambda {} statement, it should appear as: lambda { return car if car "meets whatever conditions" }.call> > That will build you a new array of cars, inside the lambda block you > can do all of your testing and return the car object if it meets your > conditions. > >> with the above i''m carrying out a number of tests against the car, and >> if it fails I want to remove that car from the array, but I don''t want >> to destroy it, e.g. I don''t want to delete it from the database. >> Unfortunately I can''t select the cars I want from SQL so I''ve got to >> do it this way. >> >> Can anyone help? >> >> thanks >> >> >> >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thank you very much for that On Jan 18, 4:35 pm, Russell McConnachie <russ...-chlIOe/xi6aw5XvHYEYAbQ@public.gmane.org> wrote:> Russell McConnachie wrote: > > hiddenhippo wrote: > >> hi, > > >> I have the following scenario within my rails code, where > >> @manufacturers is an activerecord object with many cars > > >> @manufacturers.each do |manufacturer| > >> manufacturer.cars.each do |car| > > >> end > >> end > > > @manufacturers.each do |manufacturer| > > manufacturer.cars.map! do |car| > > lambda { > > return car if car "meets whatever conditions" > > } > > end > > end > > I forgot the .call on the end of the lambda {} statement, it should > appear as: > > lambda { > return car if car "meets whatever conditions" > > }.call > > > That will build you a new array of cars, inside the lambda block you > > can do all of your testing and return the car object if it meets your > > conditions. > > >> with the above i''m carrying out a number of tests against the car, and > >> if it fails I want to remove that car from the array, but I don''t want > >> to destroy it, e.g. I don''t want to delete it from the database. > >> Unfortunately I can''t select the cars I want from SQL so I''ve got to > >> do it this way. > > >> Can anyone help? > > >> thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---