# CSV Upload Problem

**URL:** <https://www.ruby-forum.com/t/csv-upload-problem/118994>\
**Category:** Rails\
**Created:** [November 2, 2007, 12:46am UTC](https://www.ruby-forum.com/t/csv-upload-problem/118994 "2007-11-02T00:46:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [November 2, 2007, 12:46am UTC](https://www.ruby-forum.com/t/csv-upload-problem/118994/1 "2007-11-02T00:46:40Z")

</div>

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.

1. When using firefox, I’m only getting a file name. (i.e. “survey.csv”  
vs  
“/path to csv/survey.csv”).
2. 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.

---

<div class="post-metadata">

**Author:** ![jcernelli](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/73ab20/32.png) [@jcernelli](https://www.ruby-forum.com/u/jcernelli)\
**Post date:** [November 2, 2007, 2:49pm UTC](https://www.ruby-forum.com/t/csv-upload-problem/118994/2 "2007-11-02T14:49:13Z")

</div>

Just as a side note, the file can be read by fastercsv on my dev machine  
but  
the above code will not read the file.
