我想在assets/stylesheets/work.scss
view/work/index.html.erb
文件
我已经查看了这个问题
How to include a css or javascript in an erb that is outside the layout?
并在layout/application.html.erb
<head>
...
<%= yield(:header) if content_for? :header%>
</head>
然后,在index.html.erb
<% content_for :header do -%>
<%= stylesheet_link_tag 'work' %>
<% end -%>
我是以development
模式而不是production
执行此操作,为什么我需要precompile
?
答案 0 :(得分:0)
因为您是独立包含它,而不是将其包含在application.css
中。资产管道的默认值是编译applicaiton.css/application.js
以及这些文件中包含的任何内容。
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require c3
*= require purecss
*= require_self
*= require pure_css_reset
*/
如果您希望它是单独的而不是编译成一个整体文件,从stylesheet_link_tag
调用,则必须手动将其添加到预编译数组中。
http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets是一个很好的参考。