将ActiveRecord数组转换为字符串

时间:2022-09-11 17:36:09

I'm using ActiveRecord to grab an account value but I just cant get the formatting correct...

我正在使用ActiveRecord来获取帐户值,但我无法正确获取格式...

Account.all.map { |m| [m.day, m.NetLiquidation] }.unshift(['Day', 'value']).join(",") 

gives me

给我

[["Day", "value"], ["04/09/14", "94465.80"],["04/10/14", "96403.90"]]

What I need is a string like so...

我需要的是一个像这样的字符串......

"Day,value\n" + "04/09/14, 97450.57\n" + "04/10/14, 96403.90\n"

I know I'm close, but any ruby wizards know a quick shortcut?

我知道我很接近,但是任何红宝石巫师都知道快捷的捷径?

1 个解决方案

#1


0  

This should work:

这应该工作:

Account.all.map { |m| [m.day, m.NetLiquidation] }.unshift(['Day', 'value']).map(|x| x.join(",")}.flatten.join("\n")

#1


0  

This should work:

这应该工作:

Account.all.map { |m| [m.day, m.NetLiquidation] }.unshift(['Day', 'value']).map(|x| x.join(",")}.flatten.join("\n")