Long story short. I'm new to RubyOnRails. The rest of my development team has left the company and I'm the last one left. I am taking over code that they all did. How do I export the csv file to put all the data on multiple lines? Right now, the code puts multiple records into one line in the csv file.
class CancelledDealCSVGenerator
require 'csv'
def self.generate_csv(deals)
CSV.open("#{AppConfig.cancelled_csv_folder}/CANNED.CSV", "a") do |csv|
deals.each do |deal|
csv << [deal.customer_number, deal.deal_number, deal.contract_number, deal.cancel_date]
end
end
end
end
This is how it SHOULD look
999999 AAA000 55555 6/23/2011 08:27
999998 AAA001 55554 6/23/2011 08:15
开发者_如何学编程But this is how it DOES look
999999 AAA000 55555 6/23/2011 08:27 999998 AAA001 55554 6/23/2011 08:15
I'm not sure what CSV plugin/gem that you are using. If it is a simple one that simple opens a file and writes to it, this should work.
class Deal
def to_csv(delimiter=",")
[deal.customer_number, deal.deal_number, deal.contract_number, deal.cancel_date].join(delimiter)
end
end
class CancelledDealCSVGenerator
require 'csv'
def self.generate_csv(deals)
CSV.open("#{AppConfig.cancelled_csv_folder}/CANNED.CSV", "a") do |csv|
csv << deals.map(&:to_csv).join("\n")
end
end
end
From the comments it looks like your problem is not really with the RoR code but with the fact that you're looking at the file on an EBCDIC system.
You'll need to convert the files from an ASCII encoding to EBCDIC (see IBM ASCII TO EBCDIC conversion)
Basically you're looking at:
iconv -f IS08859-1 -t IBM-1047 canned.csv > converted.csv
精彩评论