0

我正在尝试在 rails3 应用程序中订购我的样式表,但我遇到了使用 *stylesheet_link_tag* 帮助程序重复行的问题。

在 app/views/layouts/application.html.erb

<%= stylesheet_link_tag    :reset, :application, :event_calendar, :cache => false %>

在生成的源代码中:

<link href="/assets/reset.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/event_calendar.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/reset.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/event_calendar.css?body=1" media="screen" rel="stylesheet" type="text/css" />

app/assets/stylesheets/ 文件夹的内容:

calendar (master *)$ ls app/assets/stylesheets/
application.css     event_calendar.css  reset.css

使用 *javascript_include_tag* 助手会出现同样的问题,我认为两者都可以相关。

4

1 回答 1

2

如果您使用的是资产管道,您只需要包含application.css在里面应该有类似...的行

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree . 
*/

不要被它注释掉的事实所迷惑,这将被处理并自动将所有文件包含在同一目录中,因为该require_tree .命令。

放...

<%= stylesheet_link_tag :application, :cache => false %>

application.css如果您需要reset.css先来,您可以指定其中的顺序

*= require reset
*= require_self
*= require_tree . 
于 2011-09-23T13:56:02.723 回答