2011-10-04 67 views
8

我无法使Rails 3.1资产管道预编译工作在生产模式下。它总是失败的SCSS中引用的图片有如下错误:Ruby on Rails 3.1资产:预编译和图像

$ bundle exec rake assets:precompile RAILS_ENV=production 
    rake aborted! 
    rails.png isn't precompiled 
    (in /home/florian/AssetTest/app/assets/stylesheets/application.css.scss) 

但是,当我看在公共/资产目录,图像是存在的,所以它是预编译:

$ ls public/assets | grep rails 
    rails-dd352fc2630e5f9aa5685ef1d7fe5997.png 

的SCSS在这种情况下,文件只是包含了一些测试代码:

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

body { 
    background: #ffffff image-url('rails.png') no-repeat 0 center; 
} 

如果我不使用SCSS中图像的URL帮手,只是URL(“/资产/ rails.png”),预编译工作正常,并manifest.yml文件是g在公共/资产上拥有。有趣的是:如果我将SCSS更改回image-url('rails.png')并运行另一个预编译,它仍然有效(我猜是因为图像现在已经列在清单文件中)。

我在这里做错了什么?我真的不想忽视辅助方法(因为使用它们是你应该这样做的方式,对吧?),我绝对不想手动创建清单文件...

回答

5

我已经我自己也会遇到同样的问题。这显然是对Rails 3.1.0的一个bug,并且有希望被固定在短期内...

在任何情况下,在production.rb,你可以试试这个:

config.assets.compile = true 

你可能有它设置到false,其中应该是。但是,如果您尝试使用SCSS中的资产助手,将其设置为false会导致问题。将该值设置为true似乎可以在使用这些助手时正确编译。

查看this issue on github了解一些详细信息。

+1

刚刚更新到Rails 3.1.1rc1建议在github问题,它的工作原理:-) – fwalch

+2

这个答案似乎不好,因为这个原因:http://stackoverflow.com/questions/8821864/config-assets-compile-真在护栏 - 生产 - 为什么 - 不 – Ringo