# Remove row from active record array

**URL:** <https://www.ruby-forum.com/t/remove-row-from-active-record-array/126485>\
**Category:** Rails\
**Created:** [January 18, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/remove-row-from-active-record-array/126485 "2008-01-18T17:18:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiddenhippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@hiddenhippo](https://www.ruby-forum.com/u/hiddenhippo)\
**Post date:** [January 18, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/remove-row-from-active-record-array/126485/1 "2008-01-18T17:18:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hiddenhippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@hiddenhippo](https://www.ruby-forum.com/u/hiddenhippo)\
**Post date:** [January 18, 2008, 5:32pm UTC](https://www.ruby-forum.com/t/remove-row-from-active-record-array/126485/2 "2008-01-18T17:32:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hiddenhippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@hiddenhippo](https://www.ruby-forum.com/u/hiddenhippo)\
**Post date:** [January 18, 2008, 5:44pm UTC](https://www.ruby-forum.com/t/remove-row-from-active-record-array/126485/3 "2008-01-18T17:44:08Z")

</div>

thank you very much for that

On Jan 18, 4:35 pm, Russell McConnachie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![hiddenhippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@hiddenhippo](https://www.ruby-forum.com/u/hiddenhippo)\
**Post date:** [January 18, 2008, 5:36pm UTC](https://www.ruby-forum.com/t/remove-row-from-active-record-array/126485/4 "2008-01-18T17:36:31Z")

</div>

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
