I am using the csv-mapper gem to import a csv file. When I use the example code on in the README (http://github.com/pillowfactory/csv-mapper) in script/console it works great. However, when I create a web form and use that to upload a csv file I get the error "No such file or directory - test.csv
These are the parameters: Parameters:
{"dump"=>{"file"=>#}, "commit"=>"Submit", "authenticity_token"=>"Hb+XDPUGyZQqB5H2vZnhlfXpEE9bAE16kAjTT34uQ3U="}
Here is what I have for my code in the controller:
def csv_import
results = CsvMapper.import(params[:dump][:file].original_filename) do
map_to Sale # Map to the Sale ActiveRecord class instead of the default Struct.
after_row lambda{|row, sale| sale.save } # Call this lambda and save each record after it's parsed.
start_at_row 1
[start_date, country]
end
flash[:notice] = "Successfully uploaded file"
end