Q:

excel import is not working with spreadsheet gem

I am using Spreadsheet gem to import excel data to database.  my view is:-
<% form_for :dump, :url=>{:action=>"excel_import"}, :html => { :multipart => true } do |f| -%>
 Select an Excel File :
 <%= f.file_field :excel_file -%>
 <%= submit_tag 'Submit' -%>
<% end -%>

and my controller is :-
require 'spreadsheet'

def excel_import
 Spreadsheet.client_encoding = 'UTF-8'
 book = Spreadsheet.open params[:dump][:excel_file]
 sheet1 = book.worksheet 0
 sheet1.each do |row|
 TimeSheet.new(:ac_no => row[0]).save
 end
end

Parameters:-
 {"utf8"=>"✓", "authenticity_token"=>"vhyy1pzYJpM9hCdgP5AiFC1Pv0UtbpLSzStZDWiZzs8=", "dump"=>{"excel_file"=>#<ActionDispatch::Http::UploadedFile:0x9a8f5f8 @original_filename="SwipeData_DeliveryTeam_Sep12.xls", @content_type="application/vnd.ms-excel", @headers="Content-Disposition: form-data; name=\"dump[excel_file]\"; filename=\"SwipeData_DeliveryTeam_Sep12.xls\"\r\nContent-Type: application/vnd.ms-excel\r\n", @tempfile=#<File:/tmp/RackMultipart20121025-4534-n7pw14>>}, "commit"=>"Submit"}

when i am trying to upload excel file and click on submit button, I am getting error:-
 can't convert ActionDispatch::Http::UploadedFile into String

I have taken the reference from blog
can anyone please tell me what is going wrong in this code. 

A:

I was having the exact same issue using the same blog reference you mentioned. 
I was able to resolve it using this reference. 
Here is your method modified to how I did mine, and mine is now working!! 
require 'spreadsheet'
require 'fileutils'
require 'iconv'

def excel_import

 tmp = params[:dump][:excel_file].tempfile

 Spreadsheet.client_encoding = 'UTF-8'

 book = Spreadsheet.open tmp.path

 sheet1 = book.worksheet 0
 sheet1.each do |row|
 TimeSheet.new(:ac_no => row[0]).save
 end
end

FileUtils.rm tmp.path

Good Luck! 
Dennis

