Nishtha Nishtha - 1 year ago 91
Ruby Question

Undefined method send_data

I am getting undefined method

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

Here is my error:

NoMethodError (undefined method `send_data' for #<Class:0x007f911933cc58>):

book =
sheet1 = book.create_worksheet :name => 'Sheet1'
sheet2 = book.create_worksheet :name => 'Sheet2'
sheet1.row(0).push "some content in Column1"
spreadsheet =

book.write spreadsheet
file = "#{Rails.root}/public/brand_store/Excelsheet"

send_data spreadsheet.string, :filename => "#{file}", :type => "application/"

Answer Source

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.