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

♀尐吖头ヾ 提交于 2021-02-07 08:01:48

问题


I have a basic static webpage.

 class StaticPagesController < ApplicationController
  def home
  end
 end

And there is a home.html.erb with just heading. This works perfectly fine in developement but the test

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

is failing with error

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

Its showing error in application.html.erb

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

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

Its working when I revome the stylesheet_link_tag.

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

This is my application.css. There are two other scss files in the stylesheet directory.

Found the problem and fixed it. But dont understand why its happening. Bootstrap had to be moved to the sass file in the same directory and there is no error. But why is it happening? Its working in developement.


回答1:


This error occurs because the app is looking for a .scss extension. As you said your filename is application.css rename it to application.css.scss and it will work.



来源:https://stackoverflow.com/questions/31891355/actionviewtemplateerror-actionviewtemplateerror-undefined-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!