似乎无法确定为什么我会得到一个未定义的方法 original_filename,试图进行文件上传以检查文件扩展名。我在这里出错的任何想法
class SpreadsheetTagService
include Roo
def initialize(uploaded_file)
open_spreadsheet(File.new(uploaded_file.tempfile.path))
read_file(open_spreadsheet)
end
private
def read_file(file)
@spreadsheet = open_spreadsheet(file)
@spreadsheet.each_with_pagename do |name,sheet|
Rails.logger.debug( sheet )
end
end
def open_spreadsheet(file)
case File.extname(file.path)
when ".csv" then Csv.new(file.path, nil, :ignore)
when ".xls" then Excel.new(file.path, nil, :ignore)
when ".xlsx" then Excelx.new(file.path, nil, :ignore)
else raise "Unknown file type: #{file.original_filename}"
end
end
end
控制器
class SpreadsheetServiceController < ApplicationController
def new
end
def create
parser = SpreadsheetTagService.new(params[:spreadsheet][:file])
respond_to do |format|
format.all {render :json => 'Done'}
end
end
end