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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jerry Van Baren
2010-Jan-04 01:19 UTC
Re: Problem with downloading a generated Excel sheet
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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ahmed Abdelsalam
2010-Jan-04 12:49 UTC
Re: Problem with downloading a generated Excel sheet
Thank you for your response, It helped me a lot. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.