【问题标题】:rake assets:precompile not working (Rails 3.1.3 edition)rake 资产:预编译不起作用(Rails 3.1.3 版)
【发布时间】:2012-01-16 03:02:08
【问题描述】:

经过审核,这个问题被问了manymanymany 次。但是我仍然不明白为什么rake assets:precompile 会失败。

我可以使用本地服务器(例如瘦)从我的浏览器查看以下结果:

body{
@include background-image(image-url('my_image.png'));
background-repeat: repeat;
    ...
    ...
}

(注意:图像路径似乎根本不起作用,我正在使用 thinkbot bourbon 作为 SCSS 库)

然而,每次我运行预编译时,我都会得到以下信息(短跟踪):

rake aborted!
images/my_image.png isn't precompiled
(in /path/to/myapp/app/assets/stylesheets/application.css.scss)

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

这个post 建议我更改我的production.rb 文件,我这样做了,它编译了我的图像并且rake 现在抱怨我有一个未定义的mixin 'border-radius'。也许这是下一个例外,但我不太确定。一切都在本地运行。

Rails Guides (3.1.3) 明确声明将该值设置为 true

'uses more memory, performs poorer than the default and is not recommended'

所以现在我有两个问题。性能降级,我的 SCSS 库现在有未定义的 mixin。

我想解决由rake assets:precompile 引起的生产部署问题。我的 Gemfile 资产组如下所示:

group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
  gem 'zurb-foundation'
  gem 'bourbon' 
 end

【问题讨论】:

  • 您找到解决方案了吗?我不明白为什么它在生产中找不到波旁威士忌。
  • 我没有。我升级到 3.2.x,它使用最新的波旁宝石。

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


【解决方案1】:

图像路径助手假定路径的images 部分,因此删除它(和斜线),它应该开始工作。

【讨论】:

  • image-url('file_name.png')image-path('file_name.png') 提供所需的结果(资产预编译)
  • 文件的实际位置(从应用程序向下)
  • 预编译会在第一个错误时退出。你得到一个未定义的 mixin 的事实表明其他东西是错误的,但我不能为我的生活解决它。当你预编译时(在它崩溃之前)你是否看到指纹图像文件出现在 public/assets 中?
  • 图像在 pub/assets 中被指纹识别。这非常令人沮丧。
  • 您可以尝试将 .erb 添加到文件中,并暂时使用asset_path 帮助器来查看是否有更多错误(线索)。
【解决方案2】:

如果您使用 assets:precompile 选项,您应该在使用 mixin 的每个样式表中使用 @import 语句。

例如

假设您在样式表中使用了 app/assets/stylesheets/partials/_mixins.css.scss 中的自定义 mixin,您应该添加

@import "partials/mixins";

到那个样式表。

我知道,不应该是这样,但目前我还没有找到其他方法。

【讨论】:

  • 感谢@joiggama。事实上,我在波旁威士忌之前已经有了这个计划。还是没有运气
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-28
  • 1970-01-01
  • 1970-01-01
  • 2012-05-20
  • 2014-04-20
相关资源
最近更新 更多