Skip to content

Instantly share code, notes, and snippets.

@danishkhan
Created October 1, 2010 00:46
Show Gist options
  • Select an option

  • Save danishkhan/605556 to your computer and use it in GitHub Desktop.

Select an option

Save danishkhan/605556 to your computer and use it in GitHub Desktop.
CSV-Mapper upload problem
class SalesController < ApplicationController
include CsvMapper
def csv_import
results = CsvMapper.import(params[:dump][:file].original_filename) do
map_to Sale
after_row lambda{|row, sale| sale.save }
start_at_row 1
[start_date, country]
end
flash[:notice] = "Successfully uploaded file"
end
end
In my Views:
<% form_for :dump, :url => {:controller => "sales", :action => "csv_import"}, :html => { :multipart => true } do |f| -%>
<table>
<tr>
<td>
<label for="dump_file">
Select a CSV File :
</label>
</td>
<td >
<%= f.file_field :file -%>
</td>
</tr>
<tr>
<td colspan='2'>
<%= submit_tag 'Submit' -%>
</td>
</tr>
</table>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment