在 Rails 中将 :pluck 或 :collect 结果转换为字符串数组的最简单方法是什么?

tha*_*y_3 -1 ruby ruby-on-rails collect pluck

我有一个名为 Record 的模型,属于 Product 模型,

所述price列类型是十六进制的。Rails 已经将其转换为字符串。但我想在我的控制台查询中获取它们。

pluck 的示例代码:

Product.first.records.pluck(:price)
Run Code Online (Sandbox Code Playgroud)

此查询将数组中的值显示为十六进制。有一种方法to_sentences 需要 pluck 值,但对我来说还不够。

问题在collect方法上是一样的:

Product.first.records.collect(&:price)
Run Code Online (Sandbox Code Playgroud)

将我的十六进制数据显示为字符串数组的 pluck 查询是什么,例如:

["45,46","75,42"]
Run Code Online (Sandbox Code Playgroud)

asi*_*niy 6

Product.first.records.pluck(:price).map(&:to_s)
Run Code Online (Sandbox Code Playgroud)