安装bootstrap gem后,Pages#welcome中的NoMethodError

安装bootstrap gem并再次运行rails server后,我收到此错误:

 NoMethodError in Pages#welcome undefined method `environment' for nil:NilClass (in /Users/neilpatel/Desktop/Rails/prospects/app/assets/stylesheets/custom.css.scss) 

custom.css.scss

 @import "bootstrap"; 

应用程序/视图/布局/ application.html.erb

    Prospects  true %>  true %>         

日志/ development.log

 Processing by PagesController#welcome as HTML Rendered pages/welcome.html.erb within layouts/application (0.1ms) Completed 500 Internal Server Error in 15ms ActionView::Template::Error (undefined method `environment' for nil:NilClass (in /Users/neilpatel/Desktop/Rails/prospects/app/assets/stylesheets/custom.css.scss)): 4:  5: Prospects 6: 7:  true %> 8:  true %> 9: 10:  app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___3923576615849785590_70354614228980' 

的Gemfile

 source 'https://rubygems.org' gem 'rails', '4.0.0.rc1' gem 'sqlite3' gem 'sass-rails', '~> 4.0.0.rc1' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 1.0.1' gem 'bootstrap-sass', '~> 3.1.1' group :doc do # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', require: false end 

应用程序/资产/ JavaScript的/ application.js中

 // This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // //= require jquery //= require jquery_ujs //= require bootstrap //= require turbolinks //= require_tree . 

更新了gemfile运行包更新

 'ran bundle update Bundler could not find compatible versions for gem "railties": In Gemfile: sass-rails (~> 4.0.2) ruby depends on railties (= 4.0.0) ruby rails (= 4.0.0.rc1) ruby depends on railties (4.0.0.rc1) 

这是sass-rails gem如何与Sprockets v2.11.1版本之后浮出的sprockets gem集成的问题(参见此处和此处 )。

要修复它,请更改Gemfile:

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

并运行bundle update

注意:您还应该更新您的Rails版本。 最新版本是v4.0.4 。 为此,请将Gemfile更改为

 gem 'rails', '~> 4.0.0' 

再次,运行bundle update