Kevin Leong
unread,Mar 18, 2011, 8:35:56 PM3/18/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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="}