I have an index.csv.erb file with the following code:
<% headers = ['PrL', 'PrG', 'UOM', 'Quantity', 'Eff.Date', 'End Date','Price','Disc', 'P', 'Gr/Net'] %>
<%= CSV.generate_line(headers).strip.html_safe %>
<% @pricelist_price_groups.each do |pricelist_price_group| %>
<% start_at = pricelist_price_group.start_at.strftime("%d/%m/%y") unless pricelist_price_group.start_at.blank? %>
<% end_at = pricelist_price_group.end_at.strftime("%d/%m/%y") unless pricelist_price_group.end_at.blank? %>
<%= CSV.generate_line([pricelist_price_group.pricelist_id,
pricelist_price_group.price_group_id,
pricelist_price_group.sale_uom_id,
start_at,
end_at,
pricelist_price_group.price,
pricelist_price_group.disc_dollar,
pricelist_price_group.disc_percent,
pricelist_price_group.price_flag,
pricelist_price_group.gross_or_net]).strip.html_safe %>
<% end %>
I add any spaces like
<% headers = ['PrL', 'PrG', 'UOM', 'Quantity', 'Eff.Date', 'End Date','Price','Disc', 'P', 'Gr/Net'] %>
<%= CSV.generate_line(headers).strip.html_safe %>
This space is then written to the CSV file. Other cases include having two spaces as a tab before<%= CSV.generate_line
This should be because it is the idea that rails are rendering. If there is a way, can I still keep spaces to keep the code clean?
source
share