Problem with downloading a generated Excel sheet

Hello,

I'm using the spreadsheet/excel gem to generate an excel sheet that I want user to be able to download it once it's generated. Please take a look on the below code:

@contacts=Contact.find(:all)       if @contacts.size>0         file="#{Date.today}_Report.xls"

        workbook=Spreadsheet::Excel.new("#{RAILS_ROOT}/public/reports/#{file}")         worksheet=workbook.add_worksheet("All Users on Database")         worksheet.write(0, 0, "First Name")         worksheet.write(0, 1, "Last Name")         worksheet.write(0, 2, "Email")         row = 2         @contacts.each do |users|           worksheet.write(row, 0, "#{users.first_name}")           worksheet.write(row, 1, "#{users.last_name}")           worksheet.write(row, 2, "#{users.email}")

          row += 1

        end

        workbook.close         send_file "#{RAILS_ROOT}/public/reports/#{file}", :type => 'text/xl; charset=utf-8; header=present', :disposition => 'attachement',:filename=>"#{file}"

The excel sheet is generated correctly, but the last line gives an error in the server, and no file is downloaded.

Here is the error: NoMethodError (undefined method `call' for nil:NilClass):

I don't know what is the nill class of the above line.

Can anyone help me?

Ahmed Abdelsalam wrote:

Hello,

I'm using the spreadsheet/excel gem to generate an excel sheet that I want user to be able to download it once it's generated. Please take a look on the below code:

[snip]

        workbook.close         send_file "#{RAILS_ROOT}/public/reports/#{file}", :type => 'text/xl; charset=utf-8; header=present', :disposition =>

         ^^ This is a typo, should be 'text/xls'?

'attachement',:filename=>"#{file}"

    ^^^^^^^^^^^ This is a typo, should be 'attachment'

The excel sheet is generated correctly, but the last line gives an error in the server, and no file is downloaded.

Here is the error: NoMethodError (undefined method `call' for nil:NilClass):

I don't know what is the nill class of the above line.

My guess is attachement.

Can anyone help me?

HTH, gvb

Thank you for your response, It helped me a lot.