我在这里创建我自己版本的 Rayan Bates CSV 截屏视频......
http://railscasts.com/episodes/396-importing-csv-and-excel
我的模型中有这个...
def self.open_spreadsheet(file)
case File.extname(file.original_filename)
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
...并在我的应用程序中收到此错误...
NameError in StudentsController#import
uninitialized constant Student::Csv
Rails.root: /home/wintas/railsApps/t4
Application Trace | Framework Trace | Full Trace
app/models/student.rb:25:in `open_spreadsheet'
app/models/student.rb:13:in `import'
app/controllers/students_controller.rb:12:in `import'
我找不到“Csv”类的初始化位置,或者它应该来自哪里。任何帮助表示赞赏。