I’m trying to use the spreadsheet gem in my Rails app, but I get the following error:
can't convert Spreadsheet::Workbook into String
This is my code:
require 'spreadsheet'
def create_spreadsheet_from_array(array)
Spreadsheet.client_encoding = 'UTF-8'
book = Spreadsheet::Workbook.new
...
end
What am I doing wrong?
My best guess from your limited details is that your code trying to output the rendered spreadsheet file in a view template. You need to use send_file in your controller. Here is a simple example (but I don’t really recommend having the spreadsheet code in the controller):