Rails 3.2和Sass不呈现Application.css

我刚刚对Rails 3.2以及最新的Sass和Coffee Rails Gems进行了重大升级,但我的Application文件不会呈现为Application.css.scss。 我在我的HTML中这样做了:

 

当我在我的开发模式中查看页面源时,我得到了

   

到底他妈发生了什么!?

它似乎将.css附加到我放在stylesheet_link_tag中的所有内容,所以如果我把它留在我的页面源代码中的’application’我有application.css等。

标签的适当格式是:

 <%= stylesheet_link_tag 'application' %> 

Rails自动将.scss文件编译为.css文件 – 然后它会自动导入正确的文件。 这一切都照顾你。

如果您没有在stylesheet_link_tag附加扩展名,则会自动附加.css 。 但是,当您指定.scss ,我不知道为什么它会附加扩展名。

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

有关详细信息,请参阅stylesheet_link_tag文档。

我认为使用Sprockets在Rails 3.2中执行此操作的“默认”方法是使用包含Sprockets清单代码的application.css(而不是application.css.scss)文件。 这应该是这样的……

application.css(app / assets / stylesheets)

 /* * 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文件的引用.rar资源的默认行为:precompile是编译你的application.js和application css

由Rail生成器生成的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' %>