https://github.com/jalagrange/excel_test_app/を取得しようとしています
しかし、ファイルはアップロードされません。次のエラーメッセージを修正しようとしています
Errno::EBADF (Bad file descriptor - C:/Sites/ExcelTestApp/public/excel_uploaded_
files/contacts.xls):
app/controllers/people_controller.rb:129:in `parse_save_from_excel'
app/middleware/flash_session_cookie_middleware.rb:19:in `call'
app/middleware/flash_session_cookie_middleware.rb:19:in `call'
people_controler.rb
def parse_save_from_excel
test_file = params[:excel_file]
file = FileUploader.new
file.store!(test_file)
book = Spreadsheet.open "#{file.store_path}"
sheet1 = book.worksheet 0
@people = []
sheet1.each 1 do |row|
p = Person.new
p.first_name = row[0]
p.last_name = row[1]
p.age = row[2]
@people << p
end
file.remove!
end
しかし、私は理解していません...
flash_session_cookie_middleware.rb
require 'rack/utils'
class FlashSessionCookieMiddleware
def initialize(app, session_key = '_session_id')
@app = app
@session_key = session_key
end
def call(env)
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
req = Rack::Request.new(env)
env['HTTP_COOKIE'] = [ @session_key,
req.params[@session_key] ]
.join('=').freeze unless req.params[@session_key].nil?
env['HTTP_ACCEPT'] = "#{req.params['_http_accept']}"
.freeze unless req.params['_http_accept'].nil?
end
@app.call(env)
end
end