I have a rails 4 application. I have the following code:
@product_types = StoreProduct.where(:store_id => @store.id).pluck(:name)
@product_data = @products.map do |product|
product[ :data ].values.reverse!
end
@product_types output looks like this: ["Color", "QTY", "TypeOf"]
@product_data output looks like this: [["RED", "17", "BOOK"]]
@products looks like: [#<Product id: 141, store_id: 146, data: {"Color"=>"RED", "QTY"=>"17", "TypeOf" => "BOOK"}>]
I want for @product_data to be sorted in the same order as @product_types. So if its QTY, Color, TypeOf as the @product_types, then the @product_data should be sorted by its keys in the same way as @product_types, so @product_data should be: 17, RED, BOOK.