Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method 'each_with_index' on Rails 5.0.3 with JRuby #533

Open
holgum opened this issue Jun 2, 2017 · 4 comments
Open

undefined method 'each_with_index' on Rails 5.0.3 with JRuby #533

holgum opened this issue Jun 2, 2017 · 4 comments

Comments

@holgum
Copy link

holgum commented Jun 2, 2017

Came across this issue when upgrading from Rails 4.2.8 to Rails 5.0.3 on JRuby 9.1.10.0.
Duplicated it from Rails console:

irb(main):006:0> s.add_row["Hello"]
NoMethodError: undefined method `each_with_index' for #<Axlsx::Row:0x72e36677>
Did you mean?  each_index
        from C:/bin/jruby-9.1.10.0/lib/ruby/gems/shared/bundler/gems/axlsx-776037c0fc79/lib/axlsx/workbook/worksheet/worksheet.rb:
781:in `update_column_info'
        from C:/bin/jruby-9.1.10.0/lib/ruby/gems/shared/bundler/gems/axlsx-776037c0fc79/lib/axlsx/workbook/worksheet/worksheet.rb:
446:in `add_row'
        from (irb):6:in `<eval>'
        from org/jruby/RubyKernel.java:1000:in `eval'
        from org/jruby/RubyKernel.java:1298:in `loop'
        from org/jruby/RubyKernel.java:1120:in `catch'
        from org/jruby/RubyKernel.java:1120:in `catch'
        from C:/bin/jruby-9.1.10.0/lib/ruby/gems/shared/gems/railties-5.0.3/lib/rails/commands/console.rb:65:in `start'
        from C:/bin/jruby-9.1.10.0/lib/ruby/gems/shared/gems/railties-5.0.3/lib/rails/commands/console_helper.rb:9:in `start'
        from C:/bin/jruby-9.1.10.0/lib/ruby/gems/shared/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:78:in `console'
        from C:/bin/jruby-9.1.10.0/lib/ruby/gems/shared/gems/railties-5.0.3/lib/rails/commands/commands_tasks.rb:49:in `run_comman
d!'
        from C:/bin/jruby-9.1.10.0/lib/ruby/gems/shared/gems/railties-5.0.3/lib/rails/commands.rb:18:in `<main>'
        from org/jruby/RubyKernel.java:961:in `require'
        from bin/rails:4:in `<main>'

Swapped out JRuby for MRI 2.3.4 and problem disappeared.
My Gemfile (before and after Rails upgrade):

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

Originally opened caxlsx/caxlsx_rails#83 but it seems like it comes from axlsx gem.

@straydogstudio
Copy link
Contributor

I've confirmed that each_with_index does not come along with Array.instance_methods with newer versions of jRuby here:

DELEGATES = Array.instance_methods - self.instance_methods - DESTRUCTIVE

@straydogstudio
Copy link
Contributor

Something else: Array.instance_methods contains each_with_index in plain irb. Only inside Rails 5 does it not show up. Now the question is if 5.1 is any different.

@straydogstudio
Copy link
Contributor

Confirmed each_with_index is also missing in Rails 5.1, and present with MRI. Rails issue: rails/rails#29329

@straydogstudio
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants