【问题标题】:css repeating using stylesheet_link_tagcss 使用 stylesheet_link_tag 重复
【发布时间】:2011-09-23 13:33:50
【问题描述】:

我正在尝试在 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* 助手会出现同样的问题,我认为两者可能相关。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 helper stylesheet-link-tag


    【解决方案1】:

    如果您使用的是资产管道,您只需要包含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 %>
    

    如果您需要reset.css 优先,您可以在application.css 中指定顺序

    *= require reset
    *= require_self
    *= require_tree . 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-05
      • 2012-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-26
      • 2021-03-10
      • 2017-04-28
      相关资源
      最近更新 更多