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:
<h1>Upload Survey</h1>
<% form_tag :action => ''upload'', :multipart => true,
:id => @survey do %>
<%=file_field "survey", "filepath"%><br>
<%= 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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---