使用 ActiveRecord 更改 table 中的所有唯一值

Change all unique values in table with ActiveRecord

我有“table”字段“数据”。此“数据”包含 属性“文本”{文本:'some_string'}。

如何使用 ActiveRecord 遍历 table 并将所有唯一文本与 'another_string' 连接起来?

假设您的数据是:
data = [ {text: "str1"}, {text: "str2"}, {text: "str1"} ]
因此,请尝试以下代码片段:

uniq_str = ""

data.each do |d|
    uniq_str = uniq_str + d[:text].to_s unless uniq_str.include? d[:text].to_s
end

puts uniq_str    # str1str2