Rails的3.2和萨斯不渲染Application.css(Rails 3.2 and Sass

2019-09-17 02:04发布

我只是做了重大升级的Rails 3.2和最新的萨斯和咖啡Rails的宝石,但我的应用程序文件不会被渲染为Application.css.scss。 我曾在我的HTML作为这样的:

  <%= stylesheet_link_tag 'application.css.scss' %>

当我在我的发展模式看页面的源代码我得到

  <link href="/assets/application.css.scss.css" media="screen" rel="stylesheet" type="text/css" />

到底他妈发生了什么!?

这似乎是追加的CSS的一切我把stylesheet_link_tag里面,所以如果我在网页源离开它,因为只是“应用”我有application.css等。

Answer 1:

该标记相应的格式是:

<%= stylesheet_link_tag 'application' %>

Rails的自动编译.scss文件转换成.css文件-然后它会自动导入正确的文件。 这一切都需要为你照顾。



Answer 2:

如果不延期追加到stylesheet_link_tag.css将自动附加。 我不知道为什么它的附加扩展名,当你指定.scss ,但是。

我也不知道为什么,你不只是使用<%= stylesheet_link_tag 'application' %> ,这应该是所有的必要。

查看文档stylesheet_link_tag 这里获取更多信息。



Answer 3:

我认为“默认”方式使用链轮是有文件名为application.css(不application.css.scss),其中包含您的链轮清单代码为此在Rails的3.2。 这应该是这个样子?

application.css(APP /资产/样式表)

/*
 * 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 main_scss_file
*/

应该有至少两行应该是它增加了内部本身的内容require_self和要求some_other_file这是耙资产你的主要SCSS文件。该默认行为参考:预编译是编译您的application.js和应用CSS

production.rb来编码铁路发生器产生指定application.css默认情况下编译。 (配置/环境)

  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
  # config.assets.precompile += %w( search.js )
  config.assets.precompile += %w( home.js )

application.erb

<%= stylesheet_link_tag 'application' %>


文章来源: Rails 3.2 and Sass not rendering Application.css