我有我的主应用程序 css,我想排除我的后端样式表,因为当 application.css 执行 *=require_tree 时,所有样式都会溢出。
我目前的文件夹设置如下:
assets/
stylesheets/
main/ #application.css ##other css files for front end
backend/ #backend.css ##other css files for back end
我的application.css如下:
/*
*= require_self
*= require foundation_and_overrides
*= require_tree ./main/
*/
后端.css
/*
*= require_self
*= require foundation_and_overrides
*= require_tree ./backend/
*/
在我的 application.rb 中
config.assets.precompile += ['application.css', 'backend.css']
我的开发.rb
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
我尝试四处移动样式表并尝试使用不同的目录,但我要么根本不加载样式表,要么收到“找不到基础和覆盖”...
有没有简单干净的方法来做到这一点? 我只是想排除几个样式表不被 application.css 编译
最佳答案
sprockets 的全部意义在于包含您需要的内容。您始终可以将另一个样式表添加到整个页面。与用户一起编译是一个很好的做法,但如果管理员使用后端,则添加另一个样式表完全没问题。
首先,application.css
已经预编译,所以你只需要:
config.assets.precompile << 'backend.css'
可选地包含一个额外的样式表,所以 application.css
有基础等backend.css
只有额外的样式:
<%= stylesheet_link_tag 'application', media: :all %>
<% if admin? %>
<%= stylesheet_link_tag 'backend', media: :all %>
<% end %>
您还可以添加 shared
如果出于某种原因 application.css
,则两者都适用的样式表目录样式会与 backend.css
冲突样式。
+ stylesheets
+ shared
+ app
+ backend
- application.css
- backend.css
和require_tree ./shared
同时。
关于css - Rails App 中的样式表范围不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19330170/