| Message: 95958 |
 |
BY: Caleb Johnson (koldrid) DATE: 2011-02-15 22:58 SUBJECT: File Upload Help I am currently having issues with configuring FasterCSV to upload a CSV file and having the information in the CSV file insert into my DB. Currently using SQLite for Development and MySQL for Production. I get the following error whenever I attempt to upload a csv file.
"Error adding logs. (some undefined method `pos' for #<ActionDispatch::Http::UploadedFile:0x1059a2b48>). Please try again."
Here are my files....
######CONTROLLER
def csv_import
FCSV.new(params[:file]).each do |row|
Script.create(:name => row[0],
:task => row[1],
:expected_results => row[2],
:require_id => row[3],
:department_id => 1,
:category_id => 1)
end
flash[:notice] = "Successfully added Script(s)."
redirect_to :action => :index
rescue => exception
# If an exception is thrown, the transaction rolls back and we end up in this rescue block
error = ERB::Util.h(exception.to_s) # get the error and HTML escape it
flash[:error] = "Error adding logs. (some #{error}). Please try again."
redirect_to :action => :index
end
######VIEW
<%= form_tag '/script_admin/csv_import', :multipart => true do %>
<%= file_field_tag "file" %><br/>
<%= submit_tag("Import") %>
<% end %>
######DB STRUCTURE
t.integer :department_id, :null => false
t.integer :category_id, :null => false
t.string :name, :null => false
t.string :task, :null => false
t.string :expected_results, :null => false
t.boolean :require_id, :null => false
t.timestamps
Any help would be appreciated. | |