twitter-bootstrap 导入 Bootstrap 时 nil:NilClass 的未定义方法“环境”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22392862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 20:17:36  来源:igfitidea点击:

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

ruby-on-railstwitter-bootstrap

提问by Ajayc

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 some dependencies (I think). I've seemingly fixed everything... except for Bootstrap.

我一直在尝试将 Bootstrap 导入到我的 rails 应用程序中,但我不太确定出了什么问题。我以前用过它,但我做了一个“捆绑更新”并破坏了一些依赖项(我认为)。我似乎已经修复了所有内容......除了 Bootstrap。

I've tried removing and re-entering the 'bootstrap-sass' gem... I can't really figure out where the error is.

我试过删除并重新输入'bootstrap-sass' gem ......我真的不知道错误在哪里。

Thanks for the help!

谢谢您的帮助!

Gemfile

文件

source 'https://rubygems.org'
ruby '2.0.0'

gem 'rails', '4.0.1'
gem 'bootstrap-sass'
gem 'bcrypt-ruby', '3.1.2'
gem 'faker', '1.1.2'

group :development, :test do

  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails', '4.2.1'
  gem 'database_cleaner', github: 'bmabey/database_cleaner'
end

gem 'sass-rails'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

Gemfile.lock

Gemfile.lock

GIT
  remote: git://github.com/bmabey/database_cleaner.git
  revision: 35bd646903fc56af185a9fa9e360c568bb56756e
  specs:
    database_cleaner (1.2.0)

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (4.0.1)
      actionpack (= 4.0.1)
      mail (~> 2.5.4)
    actionpack (4.0.1)
      activesupport (= 4.0.1)
      builder (~> 3.1.0)
      erubis (~> 2.7.0)
      rack (~> 1.5.2)
      rack-test (~> 0.6.2)
    activemodel (4.0.1)
      activesupport (= 4.0.1)
      builder (~> 3.1.0)
    activerecord (4.0.1)
      activemodel (= 4.0.1)
      activerecord-deprecated_finders (~> 1.0.2)
      activesupport (= 4.0.1)
      arel (~> 4.0.0)
    activerecord-deprecated_finders (1.0.3)
    activesupport (4.0.1)
      i18n (~> 0.6, >= 0.6.4)
      minitest (~> 4.2)
      multi_json (~> 1.3)
      thread_safe (~> 0.1)
      tzinfo (~> 0.3.37)
    arel (4.0.2)
    atomic (1.1.15)
    bcrypt-ruby (3.1.2)
    bootstrap-sass (3.1.1.0)
      sass (~> 3.2)
    builder (3.1.4)
    capybara (2.1.0)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      xpath (~> 2.0)
    childprocess (0.5.1)
      ffi (~> 1.0, >= 1.0.11)
    coffee-rails (4.0.1)
      coffee-script (>= 2.2.0)
      railties (>= 4.0.0, < 5.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.7.0)
    diff-lcs (1.2.5)
    erubis (2.7.0)
    execjs (2.0.2)
    factory_girl (4.2.0)
      activesupport (>= 3.0.0)
    factory_girl_rails (4.2.1)
      factory_girl (~> 4.2.0)
      railties (>= 3.0.0)
    faker (1.1.2)
      i18n (~> 0.5)
    ffi (1.9.3)
    hike (1.2.3)
    i18n (0.6.9)
    jbuilder (1.0.2)
      activesupport (>= 3.0.0)
    jquery-rails (3.0.4)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    json (1.8.1)
    mail (2.5.4)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.25.1)
    mini_portile (0.5.2)
    minitest (4.7.5)
    multi_json (1.9.0)
    nokogiri (1.6.1)
      mini_portile (~> 0.5.0)
    pg (0.15.1)
    polyglot (0.3.4)
    rack (1.5.2)
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (4.0.1)
      actionmailer (= 4.0.1)
      actionpack (= 4.0.1)
      activerecord (= 4.0.1)
      activesupport (= 4.0.1)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.0.1)
      sprockets-rails (~> 2.0.0)
    rails_12factor (0.0.2)
      rails_serve_static_assets
      rails_stdout_logging
    rails_serve_static_assets (0.0.2)
    rails_stdout_logging (0.0.3)
    railties (4.0.1)
      actionpack (= 4.0.1)
      activesupport (= 4.0.1)
      rake (>= 0.8.7)
      thor (>= 0.18.1, < 2.0)
    rake (10.1.1)
    rdoc (3.12.2)
      json (~> 1.4)
    rspec-core (2.14.8)
    rspec-expectations (2.14.5)
      diff-lcs (>= 1.1.3, < 2.0)
    rspec-mocks (2.14.6)
    rspec-rails (2.14.1)
      actionpack (>= 3.0)
      activemodel (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec-core (~> 2.14.0)
      rspec-expectations (~> 2.14.0)
      rspec-mocks (~> 2.14.0)
    rubyzip (0.9.9)
    sass (3.3.2)
    sass-rails (4.0.1)
      railties (>= 4.0.0, < 5.0)
      sass (>= 3.1.10)
      sprockets-rails (~> 2.0.0)
    sdoc (0.3.20)
      json (>= 1.1.3)
      rdoc (~> 3.10)
    selenium-webdriver (2.35.1)
      childprocess (>= 0.2.5)
      multi_json (~> 1.0)
      rubyzip (< 1.0.0)
      websocket (~> 1.0.4)
    sprockets (2.12.0)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-rails (2.0.1)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      sprockets (~> 2.8)
    sqlite3 (1.3.8)
    thor (0.18.1)
    thread_safe (0.2.0)
      atomic (>= 1.1.7, < 2)
    tilt (1.4.1)
    treetop (1.4.15)
      polyglot
      polyglot (>= 0.3.1)
    turbolinks (1.1.1)
      coffee-rails
    tzinfo (0.3.39)
    uglifier (2.1.1)
      execjs (>= 0.3.0)
      multi_json (~> 1.0, >= 1.0.2)
    websocket (1.0.7)
    xpath (2.0.0)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  bcrypt-ruby (= 3.1.2)
  bootstrap-sass
  capybara (= 2.1.0)
  coffee-rails (= 4.0.1)
  database_cleaner!
  factory_girl_rails (= 4.2.1)
  faker (= 1.1.2)
  jbuilder (= 1.0.2)
  jquery-rails (= 3.0.4)
  pg (= 0.15.1)
  rails (= 4.0.1)
  rails_12factor (= 0.0.2)
  rspec-rails
  sass-rails
  sdoc (= 0.3.20)
  selenium-webdriver (= 2.35.1)
  sqlite3 (= 1.3.8)
  turbolinks (= 1.1.1)
  uglifier (= 2.1.1)

回答by Aaron Cooley

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.

我也遇到了这个问题,它看起来像是与最新版本的链轮相关的问题,您可以按照建议通过更改 Gemfile.lock 来修复它,但是如果某人或某物进行了捆绑更新,它将再次损坏而且我知道有些地方不喜欢检查 Gemfile.lock 直到有一个推动阶段。

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

如果您使用比 4.0.0 更好的 sass-rails,它将解决问题...

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

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

问题解决了,它会将链轮限制为 2.11。从生成的 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)

回答by Ege Ersoz

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...

有趣的是,昨天一切都很好(我有证据,因为我昨晚睡觉前将工作版本推送到 Heroku),但今天我做了之后事情就坏了bundle update。所以我查看了它的终端输出并注意到 sprockets gem 更新到 2.12.0。然后我回去发现昨天是 2.11.0。唔...

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

凭直觉,我编辑了我的 gemfile 并添加了这一行:

gem 'sprockets', '2.11.0'

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

基本上,强制捆绑程序安装该特定版本。然后我又做了一个bundle update,瞧!事情又开始起作用了。

回答by sknight

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:

我昨天将我的项目更新到 rails 4.0.4 并收到相同的错误。运行“捆绑更新”对我没有任何帮助。卸载和重新安装 sass-rails 只安装了 4.0.1 版。我必须从以下位置更改我的 Gemfile:

gem 'sass-rails'

to:

到:

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

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

然后,在运行“捆绑更新”后,rspec 现在可以正常工作。

回答by anbiniyar

It was a gem version conflict.

这是一个 gem 版本冲突。

Please use

请用

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

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

instead of

代替

gem 'sass-rails'

gem 'sass-rails'

Perform bundle updateright after that. That should fix it

bundle update在那之后立即执行。那应该解决它

回答by James

I just ran into this issue, after updating sassto 3.3.3 and sprocketsto 2.12.0.

在更新sass到 3.3.3 和sprockets2.12.0后,我刚刚遇到了这个问题。

I ran a $ bundle outdatedto check for which gems were outdated, and indeed sass-railswas included:

我运行 a$ bundle outdated来检查哪些 gems 已过时,并且确实sass-rails包含在内:

* sass-rails (4.0.2 > 4.0.1)

Using $ bundle update sass-railssolved it for me.

使用$ bundle update sass-rails为我解决了它。

If you use $ bundle updateinstead, 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.

如果您$ bundle update改为使用,它也可以解决问题,但也会更新其他不受版本限制的 gem。一个一个地更新您的 gem 更耗时,但对于诊断 gem 冲突更有用。