Uploading of .xlsx worksheet and parsing using Roo

351 views
Skip to first unread message

Kevin Leong

unread,
Mar 18, 2011, 8:35:56 PM3/18/11
to ruby-roo
I'm trying to develop a form that parses an uploaded file

Here's my html.erb form:
<%
form_for :xlsx_import, :url=>{:controller=>"courses", :action=>"csv_import"}, :html
=> { :multipart => true } do |f| -%>
<table>
<tr>
<td>
<label for="dump_file">
Browse
</label>
</td>
<td>
<%= f.file_field :file %>
</td>
<td><%= submit_tag 'Import' %></td>
</tr>
</table>
<% end %>

The csv import function is poorly named for now. It actually parses
excel files.

Here's the code that we try to create the new file in Roo

# Create object to store excel file
parsed_file = Excelx.new(params[:xlsx_import][:file])

We're running 1.8.7 with rails 2.3.

The following error is returned:
*************************************
NoMethodError in Eportfolio/admin/coursesController#csv_import

undefined method `[]' for #<Tempfile:0x106a20d80>
RAILS_ROOT: /Users/leong/ikayzo/svn/ePortfolio/branches/
20101019_eportfolio

Application Trace | Framework Trace | Full Trace
/Users/leong/.rvm/gems/ruby-1.8.7-p330@imiloa/gems/roo-1.9.3/lib/roo/
excelx.rb:94:in `initialize'
/Users/leong/ikayzo/svn/ePortfolio/branches/20101019_eportfolio/app/
controllers/eportfolio/admin/courses_controller.rb:115:in `new'
/Users/leong/ikayzo/svn/ePortfolio/branches/20101019_eportfolio/app/
controllers/eportfolio/admin/courses_controller.rb:115:in `csv_import'
Request

Parameters:

{"xls_import"=>{"file"=>#<File:/var/folders/zq/zqn3HwaqE089g-nbMvC2+U++
+TI/-Tmp-/RackMultipart20110318-12127-1gnem5j-0>},
"commit"=>"Import",
"authenticity_token"=>"6JrtvEH9Q1N0qOY6EnlkO8WtuGLYtz0x99r/3qaU8Pw="}

Thomas Preymesser

unread,
Mar 19, 2011, 7:28:27 AM3/19/11
to ruby-roo
Hello Kevin,

this problem has nothing to do with Roo itself. Your problem is "how
do i process uploaded files with Rails". Please read your rails
documentation or ask in a rails forum!

-Thomas
Reply all
Reply to author
Forward
0 new messages