ActionView :: Template :: Error: ActionView :: Template :: Error: undefined `[] 'method for nil: NilClass

I have a basic static webpage.

class StaticPagesController < ApplicationController def home end end 

And there is home.html.erb with only a title. This works great in development, but the test

  test "should get home" do get :home assert_response :success assert_select "title","home | #{@base}" end 

with an error

 ActionView::Template::Error: ActionView::Template::Error: undefined method []' for nil:NilClass 

Showing error in application.html.erb

 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 

This is the line shown as the causing error. What causes the problem?

It works when I return stylesheet_link_tag.

  *= require_tree *= require_self @import "bootstrap-sprockets"; @import "bootstrap"; 

This is my application.css application. There are two more scss files in the styles directory.

Found a problem and fixed it. But I don’t understand why this is happening. The bootstrap should have been moved to the sass file in the same directory, and there is no error. But why is this happening? His work is in development.

+4
source share
1 answer

This error occurs because the application is looking for the .scss extension. As you said, your application.css file name will rename it to application.css.scss and it will work.

+2
source

All Articles