Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoMethodError in Pages#home undefined method `environment' for nil:NilClass

My relatively basic app was working fine then all of a sudden I ran into the following error. I have tried to solve this on my own with no luck. I thank any of you in advance for hoping me to solve this issue.

NoMethodError in Pages#home undefined method `environment' for nil:NilClass (in /Users/kevindark/Site Name/app/assets/stylesheets/application.css.scss)

The exception page indicated the problem was extracted from the stylesheet_link_tag line of code below.

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title><%= @title || "Site Name" %></title>
<%= favicon_link_tag 'favicon.ico' %>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>

Adding application.css.scss

/*
* Overwritten by RailsBricks
*
*= require_self
*/
@import "framework_and_overrides";

framework_and_overrides.css.scss available at the link below.

https://gist.github.com/kdark11/9537485

like image 470
Kevin Dark Avatar asked Mar 13 '14 21:03

Kevin Dark


1 Answers

This happened to my Rails app today as well. It was driving me crazy and your question was the only hit on Google for the problem. It turns out it was caused by the seemingly-harmless running of "bundle update" (just after adding a gem) which upgraded the 'sprockets' gem to '2.12.0'.

I forced sprockets to use the previous version with:

gem 'sprockets', '2.11.0'

in the Gemfile, then ran

bundle update

...and this solved it for me. edit: restart the server to finish, as the user below stated (thanks). Wow, if I had a dollar for every server restart during development! :-D Major changes to resources and configuration always require a server restart.

2.12.0 was only released today, so I guess it has a bug or an incompatibility with some other gems we are using. I don't know for sure, I'm a bit of a n00b myself. I hope this helps! Edit: For the record, I can verify that faker and sass are not involved as they were installed/upgraded around the same time as the breaking update and I eliminated each. I can't speak for other gems but sprockets definitely is part of the problem here.

like image 191
conorom Avatar answered Nov 01 '22 06:11

conorom