Hey all, I’m running into some problems uploading a CSV file. I have
another app that uploads photos that works fine, but for some reason
this
doesn’t work at all.
The basic setup:
View:
Upload Survey
<% form_tag :action => ‘upload’, :multipart => true, :id => @survey do
%>
<%=file_field “survey”, “filepath”%>
<%= submit_tag ‘Upload’ %>
<% end %>
Controller:
class SurveysController < ApplicationController
def upload
if request.post?
#Create a survey model with a factory method
head_surv = Survey.factory(“Head”, params[:head])
#Upload the survey file
head_surv.upload_file(params[:survey][:filepath])
end
end
end
Upload logic in a mixin:
module CsvSurveyLoader
def upload_file(file)
File.open(get_destination(), “w”) do |f|
f.write(file.read)
end
end
end
Okay there is the basic setup. I’m running into 2 problems.
- When using firefox, I’m only getting a file name. (i.e. “survey.csv”
vs
“/path to csv/survey.csv”). - A hard error:
NoMethodError in SurveysController#upload
undefined method `read’ for “C:\Users\joe\Desktop\Head1.csv”:String
I’ve been staring at this so long my head is spinning, if anyone has any
ideas I’d be really appreaciative.