comma-csv/comma

Exporting with BOM

DannyBen opened this issue · 2 comments

I was contemplating whether I should open an issue or a question on SO. Apologies if I chose poorly...

Is there anything I need to do in comma config, or the call to "render" in order to get the CSV with BOM? The reason I am asking, is that my users see gibberish when opening with Excel 2010, but it opened nicely when I added the BOM (manually).

I found this post that shows how to do it without comma, but I was hoping to get to something simpler, in the same spirit of comma. Maybe something like:

respond_to do |format|
  format.html { @activities = @activities.page(params[:page]) }
  format.csv  { render :csv => @activities, bom: true } # <--- tadaaa...
end

Perhaps this patch can be the beginning of a solution?
It is working for me, but I am not sure if it is the ideal place to put it, and I have not created any specs for it.

Usage:

# activities_controller
respond_to do |format|
  format.html { @activities = @activities.page(params[:page]) }
  format.csv  { render :csv => @activities, add_bom: true }
end

Since you found answer, I am closing this issue.

About patch, it looks good. About add_bom option, it is fine, but I like with_bom instead. I am looking for your PR!