NilClass的未定义方法

NilClass的未定义方法

本文介绍了ActionView :: Template :: Error:ActionView :: Template :: Error:nil:NilClass的未定义方法'[]'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的静态网页.

I have a basic static webpage.

 class StaticPagesController < ApplicationController
  def home
  end
 end

还有一个home.html.erb仅标题.这在开发中可以很好地完成,但需要测试

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

失败并显示错误

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

它在application.html.erb中显示错误

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?

当我删除stylesheet_link_tag时,它可以工作.

Its working when I revome the stylesheet_link_tag.

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

这是我的application.css.样式表目录中还有另外两个scss文件.

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

找到问题并解决.但是不明白为什么会这样.引导程序必须移到同一目录中的sass文件中,并且没有错误.但是为什么会这样呢?它正在发展中.

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.

推荐答案

发生此错误是因为应用程序正在寻找.scss扩展名.正如您所说的,文件名是 application.css ,将其重命名为 application.css.scss ,它将起作用.

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.

这篇关于ActionView :: Template :: Error:ActionView :: Template :: Error:nil:NilClass的未定义方法'[]'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:13