0

I'm going through Michael Hartl's Ruby on Rails Tutorial, and I have problem with running bootstrap with my application. I've searched google to fix this error but I wasn't able to find anything helpful. Can some explain me why is this error occuring?

Here you can see the error:

NoMethodError in StaticPages#home

Showing /home/mateusz/Pulpit/sample_app/app/views/layouts/application.html.erb where line #5 raised:

undefined method `environment' for nil:NilClass
  (in /home/mateusz/Pulpit/sample_app/app/assets/stylesheets/custom.css.scss)

Extracted source (around line #5):

 <html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>

Here you have home.html.erb

<div class="center hero-unit">
    <h1>Welcome to the Sample App</h1>

    <h2>
        This is the home page for the
        <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
        sample application.
    </h2>

    <%= link_to "Sign up now!", '#', class: "btn btn-large btn-primary" %>
</div>  

<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>

and also custom.css.scss

@import "bootstrap";

gemfile:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.4'
gem 'bootstrap-sass'
gem 'sprockets'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
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

and lastly application.html.erb

<!DOCTYPE html>
<html>
    <head>
        <title><%= full_title(yield(:title)) %></title>
        <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
        <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
        <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
    </head>
    <body>
        <header class="navbar navbar-fixed-top navbar-inverse">
            <div class="navbar-inner">
                <div class="container">
                    <%= link_to "sample app", '#', id: "logo" %>
                    <nav>
                        <ul class="nav pull-right">
                            <li><%= link_to "Home", '#' %></li>
                            <li><%= link_to "Help", '#' %></li>
                            <li><%= link_to "Sign in", '#' %></li>
                        </ul>
                    </nav>
                </div>
            </div>
        </header>
        <div class="container">
            <%= yield %>
        </div>
    </body>
</html>
Matthew
  • 137
  • 11

2 Answers2

0

There is a known issue in sass-rails that is causing this. https://github.com/rails/sass-rails/issues/191

Try locking sass-rails to version 4.0.3, delete Gemfile.lock and run bundle install again.

yetti
  • 141
  • 1
  • 4
0

I was having the same problem and also changed sass-rails to version 4.0.3, but did not delete Gemfile.lock. Just changing to 4.0.3 solved it for me.