Hello, I’m learning RoR on ruby tut and, on reaching Listing 5.5, I’m throwing an error (all the files are filled in accordingly for the tutorial, the error is thrown when importing the listing 5.5):

NoMethodError in StaticPages#home Showing /home/sych/rails_projects/sample_app/app/views/layouts/application.html.erb where line #5 raised: undefined method `environment' for nil:NilClass (in /home/sych/rails_projects/sample_app/app/assets/stylesheets/custom.css.scss) 

Tell me, what could be the problem and how to fix it? All files are filled according to the tutorial.

  • Are the same gems in the Gemfile as in the book? - D-side

4 answers 4

In fact, the bootstrap connection procedure is clearly described at https://github.com/twbs/bootstrap-sass

  1. Add Gemfile to Gemfile .

     gem 'bootstrap-sass', '~> 3.3.5' gem 'sass-rails', '>= 3.2' 
  2. Connect css. Add to application.css.scss the following. If there is only application.css, then rename it to .css.scss. Leaving both is bad.

     @import "bootstrap-sprockets"; @import "bootstrap"; 
  3. In application.js connect scripts

     //= require jquery //= require bootstrap 

Previous responder forgot ; when connecting styles.

  • Adding @import to .css does not make sense, as it only works in .scss. - Dahan

Try the following. In assets/stylesheets/application.css.sass add

 @import "bootstrap-sprockets" @import "bootstrap" 

Then in assets/javascripts/application.js add

 //= require bootstrap-sprockets 
  • Thanks for the answer, but application.css.sass did not help in the directory, there was only application.css. I tried and added there, then created application.css.sass, did the same thing, alas - CodeFurious
  • you just need to rename application.css to application.css.sass - Anton Bogdanov
  • I did it, a new error appeared: Sass :: SyntaxError in StaticPages # home - CodeFurious
  • Eureka, it works, now the Sass syntax error, as you have already been advised in VK, upload the project to github, so that you can understand more precisely what is wrong. - Anton Bogdanov

When connecting gem 'bootstrap-sass', '~> 3.3.5' WEBrick does not start, because the whole tutorial is based on Rails 4.0.2, and the above bootstrap draws another version of the rails, which makes hemorrhoids further study of Rails on this tutorial .

/home/maxie/.rvm/gems/ruby-2.0.0-p643@hartl/gems/bootstrap-sass-3.3.6/lib/bootstrap-sass/engine.rb:11:in `block in ': uninitialized constant Sprockets :: Rails :: VERSION (NameError) ....

and so on

Solved a problem!!! And the solution is simple, to disgrace. 1) In the Gemfile, we find the string gem 'sass-rails', '4.0.1' and change it to gem 'sass-rails', '4.0.3' 2) bundle update 3) bundle install And everything works. And you do not need to delete application.css.scss or rename it. The solution found here - Answer 4. Just do not delete Gemfile.lock works and so. And most importantly - bootstrap is not ignored as suggested by others, it connects and works

    It helped me from the foreign stackerflow.

    gem 'sprockets', '2.11.0' in Gemfile and bundle update

    May need to remove Gemfile.lock

    The bottom line is that the gem was updated to a newer version and troubles began. And the gemfile did not indicate the version of this module indicating the exact version.