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?
-- 
Posted via http://www.ruby-forum.com/.

--

You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to