如何在Rails 3.2.1中使用Controller特定的样式表? [英] How do I use Controller specific stylesheets in Rails 3.2.1?

查看:101
本文介绍了如何在Rails 3.2.1中使用Controller特定的样式表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Rails 3.2.1

Using Rails 3.2.1

我使用命令创建了一个名为Home的简单控制器:

I created a simple controller called Home using the command:

rails g controller Home index

它为我创建了一个新的控制器和视图:

And it created a new controller and view for me:

请注意,有两个样式表,一个应用程序和一个家庭。我找不到任何文档来支持这个假设,但我猜你把只适用于Home视图的样式,在Home.css.scss文件中,是否正确?

Notice how there are two stylesheets, one "Application" and one "Home". I can't find any documentation to support this assumption but I'm guessing you put styles that will only be applied to the "Home" views, in the Home.css.scss file, correct?

作为一个测试,我在Application.css.scss.erb中添加了一些全局样式并运行了应用程序。

So as a test, I added in some global styles to Application.css.scss.erb and ran the application.

接下来,我在Home.css.scss文件中添加了一些规则,我访问了一个Home / index视图,但是该文件中的样式不能作为独立的CSS引用链接,或者甚至附加到单个Application.css.scss文件。这是非常混乱的我,因为评论说:

Next, I added in some rules to the Home.css.scss file and I visited a "Home/index" view, yet the style in that file wasn't attached, neither as a seperate CSS reference link, or even appended to the single Application.css.scss file. This is highly confusing to me, since the comments say:

// Place all the styles related to the Home controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/


$ b b

为什么Home.css.scss中写的规则不应用于我的网站?

Why aren't the rules written in Home.css.scss applied to my website?

推荐答案

Home.css 仅适用于 Home 控制器操作)。不同的文件只是为了分离,使它清楚什么是CSS规则描述。您可以参阅有关资产管道的此指南。我猜你改变了默认的 application.css.scss ,并从 app / assets / stylesheets

I don't think it works that way (Home.css being applied only to Home controller actions). The different files are just for separation, to make it clearer what are the CSS rules describing. You can read this guide about the asset pipeline. I'm guessing you altered the default application.css.scss and removed the line importing all CSS files from app/assets/stylesheets.

这篇关于如何在Rails 3.2.1中使用Controller特定的样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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