Created
October 1, 2010 00:46
-
-
Save danishkhan/605556 to your computer and use it in GitHub Desktop.
CSV-Mapper upload problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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