问题
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