Shows fine locally. But when I upload to Heroku, I get the following:
在当地显示很好。但是当我上传到Heroku时,我得到以下内容:
<%= image_tag('logo-red.png') %>
and it's located in assets/images/
它位于资产/图像/
I'm not using Turbolinks. Do I need to run a command on Heroku to solve this or is there some config setting I'm missing?
我没有使用Turbolinks。我是否需要在Heroku上运行命令来解决这个问题,或者是否有一些我失踪的配置设置?
edit 1: tried running heroku run rake assets:precompile RAILS_ENV=production
编辑1:尝试运行heroku运行rake资产:预编译RAILS_ENV =生产
edit 2: response from heroku staff:
编辑2:heroku员工的回复:
It looks like your app is properly compiling that image: ~/public/assets $ pwd /app/public/assets ~/public/assets $ ls | grep logo-red logo-red-a07050d882e1dba431cef2130d39f929c611eaf8b0ec3c50db0742ddccb14d93.png
看起来您的应用正在正确编译该图像:〜/ public / assets $ pwd / app / public / assets~ / public / assets $ ls | grep logo-red logo-red-a07050d882e1dba431cef2130d39f929c611eaf8b0ec3c50db0742ddccb14d93.png
edit 3: See attached screenshot
编辑3:参见附件截图
3 个解决方案
#1
7
Try running on your local computer:
尝试在本地计算机上运行:
rake assets:precompile
rake assets:clean
Then commit and push to heroku.
然后提交并推送到heroku。
Also check your production.rb
file and make sure everything related to compiling or precompiling is true and not false ie:
还要检查你的production.rb文件并确保与编译或预编译相关的所有内容都为true而不是false,即:
config.serve_static_assets = true
config.assets.compile = true
Also, make sure rails_12factor is in your gemfile like so:
另外,确保rails_12factor在你的gemfile中,如下所示:
gem 'rails_12factor', group: :production
#2
2
Had this problem on Heroku before - we solved it by precompiling
the assets on Heroku itself:
之前在Heroku上遇到过这个问题 - 我们通过预编译Heroku本身的资产来解决它:
$ heroku run rake assets:precompile RAILS_ENV=production
I know this is done when you push the repo to Heroku; it's one of those quirks which seems to be resolved if you compile the assets on their server.
我知道当你将回购推送到Heroku时就已经完成了。如果你在他们的服务器上编译资产,这是一个似乎解决的怪癖之一。
You could also precompile locally as long as you make sure the RAILS_ENV
is production:
只要确保RAILS_ENV正在生产,您也可以在本地进行预编译:
$ rake assets:precompile RAILS_ENV=production
$ rake assets:预编译RAILS_ENV =生产
#3
0
After below answers if your problem still continuing
如果问题仍然存在,请在以下答案之后
you ca try:
你试试:
<%= asset_path 'logo-red.png' %>
#1
7
Try running on your local computer:
尝试在本地计算机上运行:
rake assets:precompile
rake assets:clean
Then commit and push to heroku.
然后提交并推送到heroku。
Also check your production.rb
file and make sure everything related to compiling or precompiling is true and not false ie:
还要检查你的production.rb文件并确保与编译或预编译相关的所有内容都为true而不是false,即:
config.serve_static_assets = true
config.assets.compile = true
Also, make sure rails_12factor is in your gemfile like so:
另外,确保rails_12factor在你的gemfile中,如下所示:
gem 'rails_12factor', group: :production
#2
2
Had this problem on Heroku before - we solved it by precompiling
the assets on Heroku itself:
之前在Heroku上遇到过这个问题 - 我们通过预编译Heroku本身的资产来解决它:
$ heroku run rake assets:precompile RAILS_ENV=production
I know this is done when you push the repo to Heroku; it's one of those quirks which seems to be resolved if you compile the assets on their server.
我知道当你将回购推送到Heroku时就已经完成了。如果你在他们的服务器上编译资产,这是一个似乎解决的怪癖之一。
You could also precompile locally as long as you make sure the RAILS_ENV
is production:
只要确保RAILS_ENV正在生产,您也可以在本地进行预编译:
$ rake assets:precompile RAILS_ENV=production
$ rake assets:预编译RAILS_ENV =生产
#3
0
After below answers if your problem still continuing
如果问题仍然存在,请在以下答案之后
you ca try:
你试试:
<%= asset_path 'logo-red.png' %>