Tuesday, 27 August 2013

Run method during CSV upload

Run method during CSV upload

I have a simple CSV uploader below that is going row by row and creating a
new record (event). I also have the unidecoder gem in use and would like
to call the to_ascii method on a field (the description field) that is in
every record being created by the CSV uploader. It sounds like it should
be simple, but I'm not familiar with iterating through a CSV file.
The uploader:
def self.import(file)
CSV.foreach(file.path, headers: true, encoding: "windows-1252:utf-8") do
|row|
Event.create! row.to_hash
end
end
Thanks!

No comments:

Post a Comment