spohlenz / tinymce-rails

Integration of TinyMCE with the Rails asset pipeline
Other
812 stars 256 forks source link

NoMethodError: undefined method `paths' for nil:NilClass #190

Closed matharvard closed 8 years ago

matharvard commented 8 years ago

I'm having an issue running this gem in production. It's a Rails 4.2.5 app running Ruby 2.2.3p173. The issue is when I call <%= tinymce %> from a view, I get the following error:

NoMethodError: undefined method `paths' for nil:NilClass
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/tinymce-rails-4.3.2/lib/tinymce/rails/configuration.rb:100:in `available_languages'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/tinymce-rails-4.3.2/lib/tinymce/rails/configuration.rb:95:in `default_language'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/tinymce-rails-4.3.2/lib/tinymce/rails/configuration.rb:68:in `options_for_tinymce'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/tinymce-rails-4.3.2/lib/tinymce/rails/configuration.rb:76:in `to_javascript'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/tinymce-rails-4.3.2/lib/tinymce/rails/helper.rb:27:in `tinymce_javascript'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/tinymce-rails-4.3.2/lib/tinymce/rails/helper.rb:19:in `block in tinymce'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionview-4.2.5/lib/action_view/helpers/capture_helper.rb:38:in `block in capture'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionview-4.2.5/lib/action_view/helpers/capture_helper.rb:202:in `with_output_buffer'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionview-4.2.5/lib/action_view/helpers/capture_helper.rb:38:in `capture'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionview-4.2.5/lib/action_view/helpers/javascript_helper.rb:68:in `javascript_tag'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/tinymce-rails-4.3.2/lib/tinymce/rails/helper.rb:19:in `tinymce'
    from (irb):1
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
... 6 levels...
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/commands/rails.rb:6:in `call'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/command_wrapper.rb:38:in `call'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:183:in `block in serve'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:156:in `fork'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:156:in `serve'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:131:in `block in run'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:125:in `loop'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application.rb:125:in `run'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.6.1/lib/spring/application/boot.rb:18:in `<top (required)>'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /usr/local/var/rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

It seems to be due to Rails.application.assets being nil when the available_languages method is called in configuration.rb. I'm able to reproduce this by creating a fresh Rails app, installing the gem, opening a console in production bundle exec rails console production, and running helper.send(:tinymce).

Any ideas on how to fix this?

spohlenz commented 8 years ago

A couple of quick ideas:

1) Are you specifying --skip-sprockets, either in the rails new command or in your ~/.railsrc? 2) Have you tried restarting Spring? 3) Does it work in development mode?

matharvard commented 8 years ago

1) Are you specifying --skip-sprockets, either in the rails new command or in your ~/.railsrc?

No, but I just tried generating a new app with --skip-sprockets, and I was able to reproduce the error the same way as above.

2) Have you tried restarting Spring?

Yes, but since it's just an issue with production, this shouldn't have an affect, right...?

3) Does it work in development mode?

Yes, perfectly fine. It seems to only be in production.

spohlenz commented 8 years ago

This looks to be due to a fairly recent change introduced in sprockets-rails 3.0.0. I will work on a proper fix but am unlikely to be able to get it resolved properly before the new year. As a workaround, you can pin sprockets-rails in your Gemfile to 2.3.3.

spohlenz commented 8 years ago

I've removed the automatic language detection in dbb107cdf40a22b9c1f25782ec501e6f2b519341 as I unfortunately saw no way of making it compatible with sprockets-rails 3.x.

rbr commented 8 years ago

I had resolved this issue by specifying the previous sprockets-rails gem version in my Gemfile: gem 'sprockets-rails', '~> 2.3.3' before finding this issue. It seems to be caused by https://github.com/rails/sprockets-rails/pull/220 which was released in sprockets-rails v3.0.0.

Just leaving this here for people chasing the same breadcrumbs i did. Correct me if I'm wrong.

I-Am-Abacus commented 8 years ago

For info, upgrading tinymce to v4.3.8 fixed this error for me. (Seems to have broken in upgrading Rails/Sprockets from 4.1.12/2.3.2 to 4.2.5/3.0.1.)

Thanks for the sterling work with this.