undefined method `environment' for nil:NilClass when importing Bootstrap

后端 未结 5 718
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 00:32

I\'ve been trying to import Bootstrap into my rails app and I\'m not quite sure what\'s going wrong. I\'ve had it working before, but I did a \'bundle update\' and destroyed

相关标签:
5条回答
  • 2020-12-08 00:42

    I ran into this exact problem today and managed to solve it.

    Funny thing is that yesterday everything was fine (of which I have proof because I pushed a working version to Heroku before going to bed last night), but today things broke after I did bundle update. So I went through the terminal output of that and noticed that the sprockets gem updated to 2.12.0. I then went back and realized that it was 2.11.0 yesterday. Hmm...

    On a hunch, I edited my gemfile and added this line:

    gem 'sprockets', '2.11.0'
    

    Basically, to force bundler to install that specific version. I then did another bundle update and voila! Things started working again.

    0 讨论(0)
  • 2020-12-08 00:43

    I ran in to this problem as well and it looks like an issue related to the latest version of sprockets and you can fix it as suggested by changing the Gemfile.lock, but if someone or something does a bundle update it's going to get broken again and I know some places don't like to check in Gemfile.lock until there's a push to stage.

    If you use sass-rails better than 4.0.0 it will resolve the problem...

    gem 'sass-rails', '~> 4.0.0'
    

    The problem is solved and it will limit sprockets to 2.11. From the generated Gemfile.lock...

        sass-rails (4.0.2)
          railties (>= 4.0.0, < 5.0)
          sass (~> 3.2.0)
          sprockets (~> 2.8, <= 2.11.0)
          sprockets-rails (~> 2.0.0)
    
    0 讨论(0)
  • 2020-12-08 00:53

    I just ran into this issue, after updating sass to 3.3.3 and sprockets to 2.12.0.

    I ran a $ bundle outdated to check for which gems were outdated, and indeed sass-rails was included:

    * sass-rails (4.0.2 > 4.0.1)
    

    Using $ bundle update sass-rails solved it for me.

    If you use $ bundle update instead, it would also solve the issue but will update other non-version-constrained gems too. Updating your gems one by one is more time-consuming, but is more useful for diagnosing the gem conflict.

    0 讨论(0)
  • 2020-12-08 00:58

    It was a gem version conflict.

    Please use

    gem 'sass-rails', '~> 4.0.0'

    instead of

    gem 'sass-rails'

    Perform bundle update right after that. That should fix it

    0 讨论(0)
  • 2020-12-08 01:06

    I updated my project to rails 4.0.4 yesterday and was receiving the same error. Running 'bundle update' did nothing for me. uninstalling and in reinstalling sass-rails only installed version 4.0.1. I had to change my Gemfile from:

    gem 'sass-rails'
    

    to:

    gem 'sass-rails', '~> 4.0.2'
    

    Then, after running 'bundle update', rspec now works as it should.

    0 讨论(0)
提交回复
热议问题