我有一个基本的静态网页。
class StaticPagesController < ApplicationController
def home
end
end
现在有一个home.html.erb文件,里面只有标题。这在开发过程中能够完美运行,但是测试时出现了问题。
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文件中。
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
这是导致错误的代码行。问题是什么?
当我删掉stylesheet_link_tag时,它可以正常工作。
*= require_tree
*= require_self
@import "bootstrap-sprockets";
@import "bootstrap";
这是我的application.css文件。在样式表目录中还有另外两个scss文件。
找到了问题并解决了它。但不理解为什么会出现这种情况。Bootstrap必须移动到同一目录下的sass文件中,才不会出错。但为什么会出现这种情况?在开发中却可以正常工作。