Ruby on Rails 3.1资产:预编译和图像

fwa*_*lch 8 ruby-on-rails-3.1 asset-pipeline

我无法让Rails 3.1资产管道预编译在生产模式下工作.它始终在SCSS中引用的图像上失败,并出现如下错误:

$ 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)
Run Code Online (Sandbox Code Playgroud)

但是当我查看public/assets目录时,图像就在那里,所以它是预编译的:

  $ ls public/assets | grep rails 
    rails-dd352fc2630e5f9aa5685ef1d7fe5997.png
Run Code Online (Sandbox Code Playgroud)

在这种情况下,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;
}
Run Code Online (Sandbox Code Playgroud)

如果我不在SCSS中使用image-url helper,而只使用url('/ assets/rails.png'),则预编译工作正常,并在public/assets中生成manifest.yml文件.

有趣的是:如果我将SCSS更改回image-url('rails.png')并运行另一个预编译,它仍然有效(我猜因为图像现在已经列在清单文件中).

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

Bar*_*aun 5

我自己遇到了同样的问题.这显然是Rails 3.1.0中的一个错误,希望可以在短时间内修复...

无论如何production.rb,你可以试试这个:

config.assets.compile = true
Run Code Online (Sandbox Code Playgroud)

你可能已将它设置为false,它应该是.但是,false当您尝试使用SCSS中的资产助手时,将其设置为导致问题.设置该值true似乎可以在使用这些帮助程序时正确地进行编译.

在github上查看这个问题了解一些细节.

  • 这个答案似乎很糟糕,原因如下:http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not (2认同)