# remove row from active record array

**URL:** <https://discuss.rubyonrails.org/t/remove-row-from-active-record-array/23462>\
**Category:** rubyonrails-talk\
**Created:** [January 18, 2008, 4:17pm UTC](https://discuss.rubyonrails.org/t/remove-row-from-active-record-array/23462 "2008-01-18T16:17:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiddenhippo](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@hiddenhippo](https://discuss.rubyonrails.org/u/hiddenhippo)\
**Post date:** [January 18, 2008, 4:17pm UTC](https://discuss.rubyonrails.org/t/remove-row-from-active-record-array/23462/1 "2008-01-18T16:17:50Z")

</div>

hi,

I have the following scenario within my rails code, where @manufacturers is an activerecord object with many cars

@manufacturers.each do |manufacturer| &nbsp;&nbsp;&nbsp;manufacturer.cars.each do |car|

&nbsp;&nbsp;&nbsp;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:** ![Russell\_McConnachie](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@Russell\_McConnachie](https://discuss.rubyonrails.org/u/Russell_McConnachie)\
**Post date:** [January 18, 2008, 4:31pm UTC](https://discuss.rubyonrails.org/t/remove-row-from-active-record-array/23462/2 "2008-01-18T16:31:47Z")

</div>

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| &nbsp;&nbsp;&nbsp;manufacturer.cars.each do |car|
> 
> &nbsp;&nbsp;&nbsp;end end

@manufacturers.each do |manufacturer| &nbsp;&nbsp;manufacturer.cars.map! do |car| &nbsp;&nbsp;&nbsp;&nbsp;lambda { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return car if car "meets whatever conditions" &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;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:** ![Russell\_McConnachie](https://avatars.discourse-cdn.com/v4/letter/r/b5ac83/32.png) [@Russell\_McConnachie](https://discuss.rubyonrails.org/u/Russell_McConnachie)\
**Post date:** [January 18, 2008, 4:35pm UTC](https://discuss.rubyonrails.org/t/remove-row-from-active-record-array/23462/3 "2008-01-18T16:35:30Z")

</div>

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| &nbsp;&nbsp;&nbsp;manufacturer.cars.each do |car|
> > 
> > &nbsp;&nbsp;&nbsp;end end
> 
> @manufacturers.each do |manufacturer| manufacturer.cars.map! do |car| &nbsp;&nbsp;&nbsp;lambda { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return car if car "meets whatever conditions" &nbsp;&nbsp;&nbsp;} end end

I forgot the .call on the end of the lambda {} statement, it should appear as:

lambda { &nbsp;&nbsp;return car if car "meets whatever conditions" }.call

---

<div class="post-metadata">

**Author:** ![hiddenhippo](https://avatars.discourse-cdn.com/v4/letter/h/65b543/32.png) [@hiddenhippo](https://discuss.rubyonrails.org/u/hiddenhippo)\
**Post date:** [January 18, 2008, 4:43pm UTC](https://discuss.rubyonrails.org/t/remove-row-from-active-record-array/23462/4 "2008-01-18T16:43:05Z")

</div>

thank you very much for that
