-1

I have a model called Record and belongs Product model,

the price column type is hexadecimal. Rails already convert it to string in view. But I wanna get them in my console queries.

Example code for pluck:

Product.first.records.pluck(:price)

This query displays the values in array as hexadecimal. There is a method called to_sentences for pluck values but its not enough for my case.

The problem is same in collect method:

Product.first.records.collect(&:price)

What is the pluck query to display my hexadecimal data as array of strings like:

["45,46","75,42"]
asiniy
  • 11,816
  • 6
  • 49
  • 117
thatway_3
  • 383
  • 1
  • 7
  • 19

2 Answers2

6
Product.first.records.pluck(:price).map(&:to_s)
asiniy
  • 11,816
  • 6
  • 49
  • 117
2

please try this:

Product.first.records.pluck(:price).join(',')
dipak gupta
  • 366
  • 2
  • 6