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

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

问题描述

我花了一天的大部分时间尝试让图像加载到我的heroku应用上。我尝试的所有东西都可以在本地使用,但在部署到heroku之后不会。

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.

我在我的资产下的images文件夹中保存了png文件。

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%;
}

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

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.

我试过切换 config.serve_static_assets = false production.rb 文件中的true和false之间,并且都不起作用。

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

预编译总是成功。

Rails 4.关于还有哪些方法可以尝试?

Rails 4. Any ideas on what else to try?

推荐答案

<另一个问题,我遇到了这个问题,那就是我在本地预先编译我的资产,然后将其加载到heroku。这要求您遵循一组不同的步骤,可以在下面找到。如果您在本地预先编译您的资产,则必须按照以下步骤进行操作,否则您对资产文件夹所做的任何更新都不会反映在产品中。

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 =生产包exec rake资产:预编译

提交推送到服务器。

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

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