Rails 4图像未在heroku上加载 [英] Rails 4 images not loading on heroku

查看:25
本文介绍了Rails 4图像未在heroku上加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一天的大部分时间试图让图像加载到我的 heroku 应用程序上.我尝试的一切都在本地工作,但在部署到 heroku 之后就不行了.

我的资产下的 images 文件夹中保存了 png 文件.我在我的 css 中使用语法引用这些图像,例如;

#signin {背景:url(<%=asset_path 'sf.png' %>);背景尺寸:100%;}

在 heroku 中,当我检查背景时,assets/sf.png 链接在那里,但是当您单击它时,它显示一个损坏的图像,表明它没有正确加载.

我尝试在 production.rb 文件中的 config.serve_static_assets = false 之间切换 true 和 false,但均无效.

我也有

组:生产做宝石'pg'宝石'rails_12factor'结尾

预编译总是成功的.

Rails 4.还有什么可以尝试的想法吗?

解决方案

另一个问题是我在本地预编译我的资产,然后再将其加载到 Heroku.这需要您遵循一组不同的步骤,如下所示.如果您在本地预编译资产,则必须遵循这些步骤,否则您对资产文件夹所做的任何更新都不会反映在 prod 中.

https://devcenter.heroku.com/articles/rails-asset-pipelinep>

RAILS_ENV=production bundle exec rake assets:precompile

commitpush 到服务器.

I have spent the better part of the day trying to get images to load on my heroku app. Everything I try works locally, but not after being deployed to heroku.

I have png files saved in the images folder under my assets. I am referencing these images with syntax in my css such as;

#signin {
  background: url(<%= asset_path 'sf.png' %>);
  background-size: 100%;
}

In heroku when I inspect the background the assets/sf.png link is there but when you click it it shows a broken image, suggesting it did not load properly.

I've tried toggling config.serve_static_assets = false in the production.rb file between true and false and neither works.

I also have

group :production do
  gem 'pg'
  gem 'rails_12factor'
end

Precompile is always successful.

Rails 4. Any ideas on what else to try?

解决方案

Another issue, I was having with this was that I was precompiling my assets locally, prior to loading it to heroku. This requires you to follow a different set of steps, which can be found below. If you precompile your assets locally, you must follow these steps or any updates you made to your assets folder will not be reflected in prod.

https://devcenter.heroku.com/articles/rails-asset-pipeline

RAILS_ENV=production bundle exec rake assets:precompile

commit and push to server.

这篇关于Rails 4图像未在heroku上加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆