Ruby on Rails 3.1资源:预编译和映像 [英] Ruby on Rails 3.1 assets:precompile and images
问题描述
我无法使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)
但是当我在public/assets目录中查找图像时,就已经对其进行了预编译:
$ 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中使用image-url帮助器,而只是使用url('/assets/rails.png'),则预编译效果很好,并且在public/assets中生成manifest.yml文件.
有趣的是:如果我将SCSS改回image-url('rails.png')并运行另一个预编译,它仍然可以工作(我想是因为该图像现在已经在清单文件中列出了)./p>
我在这里做错了什么?我真的不想忽略帮助程序方法(因为使用它们是您应该使用的方式,对吗?),我当然也不想手动创建清单文件...
我自己也遇到了同样的问题.显然,这是Rails 3.1.0中的错误,希望可以在短期内解决...
无论如何,在production.rb
中,您都可以尝试以下操作:
config.assets.compile = true
您可能已将其设置为false
会导致您在尝试使用SCSS中的资产助手时出现问题.将该值设置为true
似乎可以正确地允许在使用这些帮助程序时进行编译.
有关一些详细信息,请参见此问题github上.
I can't get the Rails 3.1 asset pipeline precompilation to work in production mode. It always fails on images referenced within SCSS with an error like:
$ 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)
But when I look in the public/assets directory, the image is there, so it is precompiled:
$ ls public/assets | grep rails
rails-dd352fc2630e5f9aa5685ef1d7fe5997.png
The SCSS file in this case just contains some test code:
/*
* 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;
}
If I don't use the image-url helper in SCSS, but just url('/assets/rails.png'), precompilation works fine, and a manifest.yml file is generated in public/assets.
The interesting thing is: if I change the SCSS back to image-url('rails.png') and run another precompilation, it still works (I guess because the image is now already listed in the manifest file).
What am I doing wrong here? I don't really want to disregard the helper methods (as using them is The Way You Should Do It, right?), and I definitely don't want to create the manifest file manually...
I've run into the same problem myself. This is apparently a bug in Rails 3.1.0, and will hopefully be fixed in short order...
In any event, in production.rb
, you can try this:
config.assets.compile = true
You likely have it set to false
, which it should be. However, having it set to false
causes issues when you use asset helpers in SCSS as you're trying to do. Setting that value to true
seems to properly allow compilation while using those helpers.
Take a look at this issue on github for some details.
这篇关于Ruby on Rails 3.1资源:预编译和映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!