这个问题在这里已有答案:
宝石更新后:测试失败,“资产未被声明为在生产中预编译” 3个答案我想在view/work/index.html.erb包含assets/stylesheets/work.scss文件
我查了这个问题
如何在布局之外的erb中包含css或javascript?
并在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 ?
This question already has an answer here:
After gem update: test fail with “Asset was not declared to be precompiled in production” 3 answersI want to include the assets/stylesheets/work.scss file in view/work/index.html.erb
I've check this question
How to include a css or javascript in an erb that is outside the layout?
and add this in layout/application.html.erb
<head> ... <%= yield(:header) if content_for? :header%> </head>Then, add this in index.html.erb
<% content_for :header do -%> <%= stylesheet_link_tag 'work' %> <% end -%>However, it threw this error
I was doing this in development mode instead of production, why I need precompile?
最满意答案
因为您是独立包含它,而不是将它包含在您的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是一个很好的参考。
Because you are including it independently, and not including it in your application.css. The default for the asset pipeline is to compile applicaiton.css/application.js and anything that is included in those files.
/* * 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 */If you want it to be seperate and not compiled into the one monolithic file, being called from your stylesheet_link_tag, you have to manually add it to the precompile array.
http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets is a good reference.
更多推荐
发布评论