Reputation: 390
I have an ActiveRecord hash like this
#<ActiveRecord::Relation [#<Tipax::Devices::MobileDevice id: 1, serial_number: "234523", imei: "22", user_id: nil>]>
How can I map this hash to an array dynamically by its columns name(serial_number, imei)
my current code for mapping is the following:
mobile_devices.map do |mobile_device|
[
mobile_device.serial_number,
mobile_device.imei,
]
end
but I want to have a method to send an array of columns (%w[serial_number imei]) and an ActiveRecord hash to generate this array from hash.
Upvotes: 1
Views: 122
Reputation: 10593
Doesn't mobile_devices.pluck(:serial_number, :imei)
do what you need?
Upvotes: 4