caxlsx_rails: Undefined method 'each_with_index' after upgrading Rails from 4.2.8 to 5.0.3

I have a simple template that was working fine before upgrading to Rails 5.0.3:

wb = xlsx_package.workbook
wb.add_worksheet(name: 'Servers') do |sheet|
	sheet.add_row ['Hostname', 'CPU Count']
end

After upgrading to Rails 5.0.3 I get:

undefined method `each_with_index' for #<Axlsx::Row:0x5e4b6ae7>
Did you mean?  each_index
Extracted source (around line #4): 
            wb.add_worksheet(name: 'Servers') do |sheet|
	sheet.add_row ['Hostname', 'CPU Count']

The problem (which I can duplicate from the Rails console) is occurring as soon as ‘add_row’ is called. My Gemfile (before and after Rails upgrade):

gem 'rubyzip', '>= 1.2.1'
gem 'axlsx', git: 'https://github.com/randym/axlsx.git', ref: '776037c0fc799bb09da8c9ea47980bd3bf296874'
gem 'axlsx_rails'

Actual version of asxlx_rails in Gemfile.lock is ‘0.5.1’ in both cases.

Any idea if this is a bug or I am missing something?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19

Most upvoted comments

I have a hack for a given Rails app. In config/application.rb, right before the Bundler.require* statement, add this line:

Array.include Enumerable

This seems rather unnecessary. But it does work.