Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

app.assets is nil during gem loading in Rails 3.1? #14

Closed
mitio opened this Issue · 7 comments

4 participants

@mitio

I just installed v0.1.0 and my Rails 3.1 app fails to boot because of this exception:

undefined method 'append_path' for nil:NilClass (NoMethodError) (in lib/rails/behaviors.rb:18)

I have no idea why app.assets is nil in this case. If I omit the rails-behaviors gem from the Gemfile and then boot (still in development mode), then Rails.application.assets is not nil (it's a Sprockets::Environment as expected) and responds to append_path.

UPDATE: I updated the app to Rails 3.1.1 and the issue is still there.

Here is the full backtrace:

/Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `append_path' for nil:NilClass (NoMethodError)
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails-behaviors-0.1.0/lib/rails/behaviors.rb:18:in `block in <class:Railtie>'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:25:in `run'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `each'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/application.rb:92:in `initialize!'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/dimitardimitrov/Projects/web/myapp/config/environment.rb:5:in `<top (required)>'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/application.rb:78:in `require_environment!'
    from /Users/dimitardimitrov/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:39:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

If you need more info, I'm available.

@mislav
Collaborator

I doubt that rails-behaviors can somehow reset "app.assets" to nil. Its railtie is as minimal as it gets.

You should try to reproduce this in a blank app. Then, figure out which part of your app may contribute to this edge case.

@mitio

@mislav, thank you so much for reminding me what a good bug report should be based on... :)

Thanks to you, I think I've found the problem — in my config/application.rb file I've replaced require 'rails/all' with:

require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"

That's because this app does not use ActiveRecord (it's backed by a MongoDB).

@mislav
Collaborator

Aren't you missing "action_view/railtie" there

@mitio

Yeah, it is missing. I will add it and I think this issue can be closed. Thanks for the help.

@mitio mitio closed this
@mitio mitio reopened this
@mitio mitio closed this
@mitio

Just a note that require 'action_view/railtie' does not solve the issue.

If someone else is experiencing the same problem, you should add the following to the list of stuff to load:

require 'sprockets/railtie'

For more info, consult with railties/lib/rails/all.rb to see what Rails loads by default, so that you don't miss something important :)

@x2002g

Thanks a lot. It resolves my problem perfectly :)

@deln2403

Thanks for the solution mitio!

Posting a different backtrace which was resolved the same way. Took me forever to find this discussion and solution...

$ rails g ember:install --head
/home/username/.rvm/gems/ruby-2.0.0-p247/bundler/gems/ember-rails-37f7d1269f87/lib/ember_rails.rb:34:in `block in <class:Railtie>': undefined method `append_path' for nil:NilClass (NoMethodError)
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from /home/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
    from /home/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from /home/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from /home/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from /home/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from /home/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/username/delorme.nic@gmail.com/Aptana Studio 3 Workspace/username.v0.0.7/config/environment.rb:5:in `<top (required)>'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
    from /home/username/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:45:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.