I am implementing in Ruby on Rails and I just want something easy to do, i just want to read a csv file and then show the output in a view. I have some code which seems good to me, but i always get the errror : can't convert Tempfile into String This is my controller:
def match
file = params[:file]
@original_filename = file.original_filename
tmpfile = Tempfile.new("redmine_project_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
session[:importer_tmpfile] = tmpfilename
sample_count = 5
i = 0
@samples = []
FasterCSV.open(file, "r") do |row|
@samples[i] = row
i += 1
if i > sample_count
break
end
end
and my view is just:
<% form_tag({:action => 'result'}, {:multipart => true}) do %>
<table>
<% @samples.each do |sample| %>
<tr>
<td>sample</td>
</tr>
<% end %>
</table>
Someone who can help me out? Greetz