将Rails应用程序上传到heroku后图像被破坏

时间:2015-10-02 19:57:02

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

在本地显示正常。但是当我上传到Heroku时,我得到以下内容:

enter image description here

<%= image_tag('logo-red.png') %>

它位于assets / images /

我没有使用Turbolinks。我是否需要在Heroku上运行命令来解决这个问题,或者是否有一些我不知道的配置设置?

编辑1:尝试运行heroku run rake assets:precompile RAILS_ENV=production

编辑2:来自heroku员工的回复:

看起来您的应用正在正确编译该图片: 〜/ public / assets $ pwd /应用/公/资产 〜/ public / assets $ ls | grep logo-red 标志 - 红 - a07050d882e1dba431cef2130d39f929c611eaf8b0ec3c50db0742ddccb14d93.png

编辑3:参见随附的屏幕截图 enter image description here

3 个答案:

答案 0 :(得分:7)

尝试在您的本地计算机上运行:

rake assets:precompile
rake assets:clean

然后提交并推送到heroku。

同时检查您的production.rb文件并确保与编译或预编译相关的所有内容均为true且不为false,即:

config.serve_static_assets = true
config.assets.compile = true

另外,请确保rails_12factor在您的gemfile中,如下所示:

gem 'rails_12factor', group: :production

答案 1 :(得分:2)

之前在Heroku上遇到过这个问题 - 我们通过precompiling Heroku本身的资产解决了这个问题:

$ heroku run rake assets:precompile RAILS_ENV=production

我知道当你将回购推送到Heroku时就已经完成了。如果你在他们的服务器上编译资产,它似乎可以解决这些怪癖之一。

只要确保RAILS_ENV生产:

,您也可以在本地进行预编译

$ rake assets:precompile RAILS_ENV=production

答案 2 :(得分:0)

如果您的问题仍然存在,请在以下答案之后

你可以尝试:

<%= asset_path 'logo-red.png' %>