https://github.com/christoph88/kratos/tree/create-landingpage
我无法在 heroku 的生产环境中从我的 CSS 文件加载图像。在我的开发服务器上,它运行完美。
我试过这样做:
#config/environments/production.rb
config.assets.compile = true
config.assets.digest = true
#cmd
rake assets:precompile RAILS_ENV=production
git add.
git commit -a -m "Your Commit"
git push heroku master
heroku run rake assets:precompile --app your_heroku_app
没有效果。
图像存储在 assets/images 文件夹下。加载图像的 css 文件位于/vendor/stylesheets/landingpage/style.css 下
这是一个 .css 文件,所以我没有为图像使用 ruby 或 sass 助手,而只是使用例如网址(bgTop.jpg)
我尝试将文件重命名为 .css.scss 并使用 image-url("bgTop.jpg") 助手,但这也没有效果。
最佳答案
我成功地将我的 css 文件重命名为 .css.scss 并使用 image_url( 助手。接下来在助手中我需要将子目录放在 image_url("landingpage/bgTop.jpg ")
我还需要将所有图像子目录添加到 Assets 管道。
application.rb
# add all asset pipeline images sub folders
Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
config.assets.paths << path
end
并在 production.rb
中启用一些东西 # Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# Generate digests for assets URLs.
config.assets.digest = true
关于css - heroku 不从供应商 .css 文件加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29729125/