未定义的方法send_data

在电子表格中创build多个选项卡时,我得到了未定义的方法send_data 。 我无法理解使用send_Data方法发送的数据。

这是我的错误:

 NoMethodError (undefined method `send_data' for #<Class:0x007f911933cc58>): book = Spreadsheet::Workbook.new sheet1 = book.create_worksheet :name => 'Sheet1' sheet2 = book.create_worksheet :name => 'Sheet2' sheet1.row(0).push "some content in Column1" spreadsheet = StringIO.new book.write spreadsheet file = "#{Rails.root}/public/brand_store/Excelsheet" send_data spreadsheet.string, :filename => "#{file}", :type => "application/vnd.ms-excel" 

send_data是用来呈现二进制数据格式的浏览器,在rails model是不可访问的这里是send_data方法的官方文档。

在你的情况下,我猜你写了你的Excel文件生成codemodel ,所以只需返回Spreadsheet对象,并在控制器中编写代码来呈现您的Excel文件,或者您可以将其保存到临时文件,并通过提供该文件path在send_data方法中。

希望这会有所帮助。