Nishtha Nishtha - 4 months ago 32
Ruby Question

Undefined method send_data

I am getting undefined method

send_data
when creating multiple tabs in spreadsheet. I am not able to understand what data should be sent using this
send_Data
method.

Here is my error:

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"

Answer

send_data is used to render binary data format to browser, it is not accesible in rails model Here is the official documentation for the send_data method.

In your case, I guess you wrote your Excel file genration code in model, So just return the Spreadsheet object and write code in controller for render your excel file or you can save it into temp file and render it from controller by providing that file path in send_data method.

Hope this will help.