【问题标题】:Ruby on Rails 3.1 assets:precompile and imagesRuby on Rails 3.1 资产:预编译和图像
【发布时间】:2011-11-30 15:40:32
【问题描述】:

我无法让 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') 并运行另一个预编译,它仍然可以工作(我猜是因为图像现在已经在清单文件中列出)。

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

【问题讨论】:

    标签: ruby-on-rails-3.1 asset-pipeline


    【解决方案1】:

    我自己也遇到过同样的问题。这显然是 Rails 3.1.0 中的一个错误,希望能在短期内得到修复……

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

    config.assets.compile = true
    

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

    查看this issue on github 了解更多详情。

    【讨论】:

    猜你喜欢
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-20
    • 2012-06-03
    相关资源
    最近更新 更多