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:

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.

thank you very much for that

On Jan 18, 4:35 pm, Russell McConnachie [email protected]

Russell McConnachie wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs