i am implementing a few weeks now in Ruby. And what i want to do is read in a csv file, which i put then in a temporary file so i can access it in next views and manipulate the data. I have implemented everything like examples on the internet, but i always get the error : undefined method `original_filename’ for nil:NilClass
My code in my view is:
<% form_for :dump, :url=>{:controller=>"project_importer", :action=>"match"}, :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>
</table>
and then in my controller i have:
file = params[:file]
@original_filename = file.original_filename
tmpfile = Tempfile.new("redmine_user_importer")
if tmpfile
tmpfile.write(file.read)
tmpfile.close
tmpfilename = File.basename(tmpfile.path)
if !$tmpfiles
$tmpfiles = Hash.new
end
$tmpfiles[tmpfilename] = tmpfile
else
flash[:error] = "Cannot save import file."
return
end
I really don’t know what i am doing wrong, i hope someone can help me out. The file param is not empty.
Thanks in advance!
try
instead of
Or print
on the target page to inspect your params if this doesnt work.