Rails:Application.css是否加载所有css.scss文件? [英] Rails: Does Application.css load all css.scss files?

查看:47
本文介绍了Rails:Application.css是否加载所有css.scss文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到application.css中的以下行包括树中的所有css文件

I read that the following line in application.css includes all the css files in the tree

*= require_tree . 

我的困惑是,从我发现的错误中发现错误(请纠正我),如果我想在与控制器渲染匹配的css文件加载时,需要将以下行添加到application.haml中他们:

My confusion is that, from what I have found out (please correct me if I am wrong), I need to add the following line into my application.haml if I want css files to load when they match with the controller rendering them:

    = stylesheet_link_tag params[:controller]

疑问1:我真的需要添加此行吗?我认为这是按照惯例自动完成的.(我想答案是肯定的,我需要包括这一行)

Doubt1: Do I really need to add this line? I thought it was done automatically by convention. (I am guessing the answer to this is yes, I need to include this line)

问题2:由于application.css由于"require_tree"而加载了所有css文件,是否会导致与其他css文件之间发生某种冲突/混乱?

Doubt2: Since the application.css loads all the css files due to "require_tree .", would cause some kind off conflicts/messing about with each of the other css files?

Doubt3:如果我想使用require_tree加载该目录中的所有框架文件,并且在屏幕呈现时加载特别是控制器css会怎样.

Doubt3: What if I wanted to use the require_tree to load all of the skeleton files in that directory, and when a screen renders, to load in particular the controller css.

例如,

我有:

  • application.css
  • some_basic_styling.css
  • home.css.scss
  • invitation.css.scss

我的application.css将包含所有css文件(由于require_tree).home.css应该由home控制器加载,而Invitation.css应该由邀请控制器加载.我需要采取什么步骤来确保这一点?

My application.css would include all of the css files (due to require_tree). The home.css is meant to load by the home controller, and the invitation.css is supposed to be loaded by the invitation controller. What steps do I need to ensure this?

推荐答案

在带有资产管道的Rails 3.1中,有一个默认的链轮命令 require_tree.将所有文件加载到app/assets/stylesheets/和将其编译为application.css.

In Rails 3.1 with asset pipeline there's a default sprocket command require_tree . that loads all the files in app/assets/stylesheets/ and compiles it into application.css.

= stylesheet_link_tag params [:controller] 命令基本上将其输出到您的视图中.

The = stylesheet_link_tag params[:controller] command basically outputs this into your views.

= stylesheet_link_tag :products 如果从产品控制器查看.

= stylesheet_link_tag :products if viewing from the products controller.

不需要 来获取所有要编译到application.css中的文件.默认情况下,所有文件都会自动编译到application.css中.

This is not needed to get all the files to be compiled into application.css. All files are automatically compiled into application.css by default.

每个控制器都需要样式表的用例是 require_tree..基本上,您不希望所有内容都在一个样式表中进行编译.与默认设置相反.

The use case of requiring a stylesheet per a controller is if you don't require_tree .. Basically, you don't want everything compiled in one stylesheet. It's the opposite of the default.

这篇关于Rails:Application.css是否加载所有css.scss文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆