私はルビー1.9.2を使用していCSVファイルに書き込み、またlibrary.Iが適切にちょうどが正しく
この
name,country_code,destination,code
Afghanistan,93,Bamain,51
Afghanistan,93,Bamain,52
Afghanistan,93,Bamain,53
Afghanistan,93,Parwan,91
私のコードのようなCSVファイルに書きたいのCSVを使用する方法この
ですdef export_data
@coun = Country.all(:limit => 10)
header = "name,country_code,destination,code"
file = "my_file.csv"
File.open(file, "w") do |csv|
csv << header
@coun.each do |c|
csv << [c.name, c.country_code, c.user_id, c.subscriber_id]
# How puts line break here
end
end
send_file(file)
end
私は、私はCSVファイルであっ壊し、また、このため息を省略ライン置く方法上記の言及を持っている
カバーCSV内のすべての行事前に "[]"
Like ["Finland",1,1,2334]
おかげ..
この作業の理由たぶん、あなたは説明できますか? – Tommyixi