remove row from active record array

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

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.

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

thank you very much for that