我正在尝试以CSV格式呈现由@people变量定义的数组。当我在我的Controller中使用以下代码时,它返回一个填充了对象ID列的CSV文件(即0x59ff1c0)。我做错了什么?
def index
@filter_criteria = lambda { |ped| (ped.id.nil? || ped.mother_id.nil?) }
@people = BuildList.build_list.persons.find_all(&@filter_criteria)
respond_to do |format|
format.html
format.csv { send_data @people.to_csv }
end
end
答案 0 :(得分:0)
我有一个类似的问题,直到我把它放在我的桌子的模型中,
def self.to_csv(options = {})
CSV.generate(options = {}) do |csv|
csv << column_names
all.each do |report|
csv << report.attributes.values_at(*column_names)
end
end
end
数据@report在此处理时不是数组:
format.xls {send_data @report.to_csv(col_sep: "\t") }
我得到了我想要的数据,但是标签分隔工作不正常(还)