Search by select query(or alternative) using array

217 Views Asked by At
get_srv_id = Service.find_all_by_objt_id(page_records.collect(&:objt_id))

From this request, I'm getting ID's that I need to check:

[5152, 3876]

The next step is to compare and select only those values where srv_id matches.

int_service_attributes.select {|element| element.srv_id == get_srv_id.each {|elem| elem.id} }

But this is now working as get_srv_idis an array.

int_service_attributes is used as a class method has many.

Ruby: 1.8.7

Rails: 2.3.4

Yes, I do know that the version are old like dinosaurs, but there is no availability to upgrade now.

1

There are 1 best solutions below

0
Viktor On

Thanks for solution Sebastian Palma

The answer is:

int_service_attributes.select {|element| get_srv_id.include?(element.srv_id) }