[英]how to use spreadsheet gem in rails 4?
Currently I am upgrading my Rails app from rails 3 to rails 4 and i am using spreadsheet(0.7.1) after running server I got undefined method `send_file' for main::object this is my code: 目前,我正在将Rails应用程序从Rails 3升级到Rails 4,并且在运行服务器后,我使用电子表格(0.7.1) 来获取main :: object的未定义方法“ send_file”,这是我的代码:
def financial_export_excel
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet
sheet.merge_cells(5, 0, 6, 0)
sheet.merge_cells(5, 1, 6, 1)
sheet.merge_cells(5, 2, 6, 2)
sheet.merge_cells(5, 3, 6, 3)
sheet.merge_cells(5, 4, 6, 4)
sheet.merge_cells(5, 5, 6, 5)
sheet.merge_cells(5, 6, 6, 6)
sheet.merge_cells(5, 7, 6, 7)
sheet.merge_cells(5, 8, 6, 8)
book.write "sample.xls"
send_file "sample.xls"
File.delete "sample.xls"
end
any help on this? 有什么帮助吗?
It seems your are storing the file in location and send it for download and finally delete it. 看来您正在将该文件存储在本地,然后将其发送以进行下载,最后将其删除。
Since you deleted the file you con't get it for download. 由于您删除了文件,因此无法下载。 If you remove the line 如果删除线
File.delete "sample.xls"
it will work. 它会工作。
or you can use send_data
method instead of send_file
method. 或者您可以使用send_data
方法代替send_file
方法。
eg: 例如:
send_data book, :filename => "sample.xls", :type => "application/vnd.ms-excel" send_data图书,:filename =>“ sample.xls”,:type =>“ application / vnd.ms-excel”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.