rails 3.1生成CSV文件 [英] rails 3.1 generating CSV file
本文介绍了rails 3.1生成CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将表格资料汇出为CSV档案,但每个纪录后面都有一个空白列。为什么以及如何解决此问题?
I am able to export table data to a CSV file, however there is a blank row after every record. Why and how do i fix it?
在index.html.erb
in index.html.erb
<%= link_to "Export to csv", request.parameters.merge({:format => :csv})%>
in index.csv.erb
in index.csv.erb
<%- headers = ["Id", "Name"] -%>
<%= CSV.generate_line headers %>
<%- @customers.each do |n| -%>
<%- row = [ n.id, n.fname ] -%>
<%= CSV.generate_line row %>
<%- end -%>
推荐答案
b
$ b
This is what fixed it.
<%= CSV.generate_line row, :row_sep => ?\t, :quote_char => ?\ %>
这篇关于rails 3.1生成CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文