kannathasan
kannathasan

Reputation: 573

how to use spreadsheet gem in rails 4?

Currently I am upgrading my Rails app from rails 3 to rails 4 and i am using spreadsheet(0.7.1) after running server I got undefined method `send_file' for main::object this is my code:

def financial_export_excel
    book = Spreadsheet::Workbook.new
    sheet = book.create_worksheet
    sheet.merge_cells(5, 0, 6, 0)
    sheet.merge_cells(5, 1, 6, 1)
    sheet.merge_cells(5, 2, 6, 2)
    sheet.merge_cells(5, 3, 6, 3)
    sheet.merge_cells(5, 4, 6, 4)
    sheet.merge_cells(5, 5, 6, 5)
    sheet.merge_cells(5, 6, 6, 6)
    sheet.merge_cells(5, 7, 6, 7)
    sheet.merge_cells(5, 8, 6, 8)
    book.write "sample.xls"
    send_file "sample.xls"
    File.delete "sample.xls"
end

any help on this?

Upvotes: 1

Views: 1356

Answers (1)

Arivarasan L
Arivarasan L

Reputation: 9958

It seems your are storing the file in location and send it for download and finally delete it.

Since you deleted the file you con't get it for download. If you remove the line

File.delete "sample.xls"

it will work.

or you can use send_data method instead of send_file method.

eg:

send_data book, :filename => "sample.xls", :type => "application/vnd.ms-excel"

reference send_data

Upvotes: 1

Related Questions