【问题标题】:Asset is not precompiled in RoR Openshift app资产未在 RoR Openshift 应用程序中预编译
【发布时间】:2013-05-08 09:44:18
【问题描述】:

我有一个 Ruby on Rails OpenShift 应用程序(ruby 1.9,Rails Rails 3.2.13),在开发环境中运行没有问题。但是,当我将应用程序部署到 OpenShift 时,我收到以下错误:

ActionView::Template::Error (logo.png isn't precompiled):
    2:   <header>
    3:     <div id="header" class="clearfix landing_header">
    4:       <a href="#" id="logo">
    5:         <%= image_tag("logo.png") %>
    6: 
    7:       </a>

我了解错误提示 logo.png 未预编译。这是有道理的,因为这些指令是在我的 production.rb 环境中设置的:

config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true

嗯,我的资产是预编译的吗?当我部署我的应用程序(使用git push)时,我可以看到:

remote: Precompiling with 'bundle exec rake assets:precompile'

而且没有错误...即使我使用 SSH 在 OpenShift 存储库中搜索预编译的资产,我也可以在那里看到它,与许多其他资产一样:

> ls public/assets | grep logo
logo-66589ea9e7a1caa7f2151a721d6cdbd2.png

当我在浏览器中点击我的应用程序地址/资产/该文件 ^^ 时,我可以看到它。唯一的问题是 image_tag 没有。

我做错了什么?资产是预编译的,不是吗?我是否错误地使用了 image_tag?提前致谢!

【问题讨论】:

标签: ruby-on-rails asset-pipeline assets production-environment openshift


【解决方案1】:

在本地系统上预编译资产,然后推送代码。肯定会成功的。

【讨论】:

  • 也许会,但是……OpenShift 不应该为我预编译资产吗?无论如何,预编译的资产文件都在所需的位置,只有 Rails 应用程序没有这样说。
  • 好吧,但那有什么问题呢? OpenShift 中的错误?
【解决方案2】:

回答有点晚了,但我也遇到了一些问题,这就是我解决它的方法。当我对 oepnshift 执行“git push”时,它会预编译控制台中看到的资产

remote: Precompiling with 'bundle exec rake assets:precompile'

问题我相信这是使用我的开发设置进行预编译,而不是生产设置。为了解决这个问题,我在部署操作挂钩文件(app -> .openshift -> action_hooks - deploy)中添加了几行

cd $OPENSHIFT_REPO_DIR
RAILS_ENV=production bundle exec rake assets:precompile

这会强制它使用生产配置文件进行预编译。

现在唯一的问题是,当我执行 git push 时,它会预编译两次,一次是 openshift 的开箱即用,第二次是动作挂钩。不过应该还是可以的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-30
    • 2014-11-13
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    相关资源
    最近更新 更多