I am getting undefined method
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
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.