In my controller, I'm creating an array of strings. I'd like to create a CSV which simply has each element of the array on a new line. They are already strings that are comma separated.
I've been trying to create the CSV file with this code in my controller:
#controller
@metrics = ["Group Name,1", "25", "44,2,5"]
respond_to do |format|
format.html
format.csv { send_data @metrics.to_csv, filename: "output.csv" }
end
And this code in my model:
#model
def self.to_csv(options = {})
CSV.generate(options) do |csv|
all.each do |row|
csv << row.attributes.values
end
end
end
However, this outputs to my CSV file without the lines separated.
"Group Name,1", "25", "44,2,5"
The output I'd like to see is simply:
"Group Name,1"
"25"
"44,2,5"
Any thoughts on how to properly handle this? Thanks in advance.