在heroku上未加载Rails 4图像 [英] Rails 4 images not loading on heroku
问题描述
我花了一天的大部分时间试图让图像加载到我的 heroku 应用程序上.我尝试的一切都在本地工作,但在部署到 heroku 之后就不行了.
我在我的资产下的图像文件夹中保存了 png 文件.我在我的 css 中使用语法引用这些图像,例如;
#signin {背景: url(<%= asset_path 'sf.png' %>);背景尺寸:100%;}
在 heroku 中,当我检查背景时,assets/sf.png 链接在那里,但是当您单击它时,它显示一个损坏的图像,表明它没有正确加载.
我尝试在 production.rb
文件中的 true 和 false 之间切换 config.serve_static_assets = false
,但都不起作用.
我也有
group :production do宝石'pg'宝石'rails_12factor'结尾
预编译总是成功的.
Rails 4. 还有什么可以尝试的想法吗?
我遇到的另一个问题是,在将资产加载到 heroku 之前,我正在本地预编译我的资产.这要求您遵循一组不同的步骤,这些步骤可以在下面找到.如果您在本地预编译资产,则必须执行这些步骤,否则您对资产文件夹所做的任何更新都不会反映在 prod 中.
https://devcenter.heroku.com/articles/rails-asset-pipeline>
RAILS_ENV=production bundle exec rake assets:precompile
commit
和 push
到服务器.
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.
这篇关于在heroku上未加载Rails 4图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!