Reputation: 15107
I have a csv file with about 30 columns that i would like to output, and would like these to appear in my .csv.erb on different lines, for example:
<%= quantity.line_number %>,
<%= quantity.created_at.strftime("%Y-%m-%d %H:%M:%S") %>,
<%= quantity.partner_entity_no %>,
<%= quantity.partner_name %>,
However when I execute this then my .csv file has line breaks after every ',' I would like to 1) keep each column on separate line in source and 2) have non line breaks in the output .csv file. How could I make this happen?
Upvotes: 1
Views: 361
Reputation: 20408
Use the stdlib CSV class to get csv quoting and escaping semantics right. Or more conveniently, use its Array#to_csv helper method.
<% require 'csv' %>
...
<%= [
quantity.line_number,
quantity.created_at.strftime("%Y-%m-%d %H:%M:%S"),
quantity.partner_entity_no,
quantity.partner_name,
].to_csv %>
Upvotes: 2
Reputation: 31574
<%= [quantity.line_number,
quantity.created_at.strftime("%Y-%m-%d %H:%M:%S"),
quantity.partner_entity_no,
quantity.partner_name].join(',') %>
Upvotes: 2