Using Rails 6.
My dirty code
active_card_ids = JSON.parse(cookies[:card_ids])
@active_cards = []
@best_cards = Houses.where("#{payment_category} IS NOT NULL").order("#{payment_category} DESC")
@best_cards.each do |card|
if active_card_ids.include? card.id
@active_cards << card
end
end
What I am trying to do
I have an array of records queried: queried_records = [<object id: 1>, <object id: 3>, <object id: 4>, <object id: 7>]
Another array of IDs: wanted_ids = [4, 5]
Create another array: selected_records = []
I want to move queried_records found in wanted_ids, to selected_records.
In this example, we found <object id: 4> from queried_records, so we want to move (not copy) it to selected_records.
The results should be selected_records return an array [<object id: 4>]