Como escrever no arquivo CSV corretamente
Eu estou usando ruby 1.9.2 e também usar sua biblioteca csv.Eu quero escrever em csv corretamente apenas
como isso
name,country_code,destination,code
Afghanistan,93,Bamain,51
Afghanistan,93,Bamain,52
Afghanistan,93,Bamain,53
Afghanistan,93,Parwan,91
Meu código é esse
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
Eu tenho mencionado acima como puts i line quebrar lá no arquivo CSV e também omitir este suspiro que
abrange todas as linhas em CSV "[]"
Like ["Finland",1,1,2334]
Desde já, obrigado..