未提供Rails Cloudfront资产 [英] Rails Cloudfront assets not served
问题描述
我使用Heroku for Rails设置Cloudfront,一开始它运行良好。我在最后几天注意到资产不再从cloudfront.net提供服务。
Production.rb
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config .action_controller.perform_caching = true
config.action_controller.asset_host ='http://d2t6o5tnu5etuf.cloudfront.net'
config.serve_static_files = true
config.assets.js_compressor =:uglifier
config.assets.css_compressor =:sass
config.assets.compile = true
config.assets.digest = true
config.assets.version ='1.0'
config .log_level =:info
config.i18n.fallbacks = true
config.active_support.deprecation =:notify
config.log_formatter = :: Logger :: Formatter.new
config。 active_record.dump_schema_after_migration = false
end
我可以在云端地址下找到我的所有资产,在铬我可以看到应用程序5de b6995ce9b984d469b27c58cc92a095d19cd13e0acd622ffe426c41826e055.js从云端服务器获取。然而,页面上的所有静态图像例如/assets/shop/banners/2.jpg不要。
它似乎与预编译有关,因为它不查找指纹文件的版本,或者?
在我的gem文件中,我有以下内容:
group:production,:staging do
gem'rails_12factor'
gem'pg'
end
随着tegon的发展,需要image_tag或image_url来为cloudfront中的资产提供服务。我在我的代码中有通常的img src引用,它不会被识别。
将img src更改为image_tag或image_url,它正在工作。谢谢!
I set-up Cloudfront with Heroku for Rails and in the beginning it worked fine. I noticed in the last days that the assets are not served from cloudfront.net any longer.
Production.rb
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.action_controller.asset_host = 'http://d2t6o5tnu5etuf.cloudfront.net'
config.serve_static_files = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
I can reach all my assets under the cloudfront adress and in chrome i can see that application-5deb6995ce9b984d469b27c58cc92a095d19cd13e0acd622ffe426c41826e055.js gets served from cloudfront server. However all static images on the page e.g. /assets/shop/banners/2.jpg do not.
It seems to have to do with the precompiling, since it does not look for the fingerprint version of the file, or?
In my gem-file I have the following included:
group :production, :staging do
gem 'rails_12factor'
gem 'pg'
end
As tegon poined out, image_tag is or image_url is needed to serve the assets from cloudfront. I had the usual "img src" reference in my code, which will not be recognized.
Changed img src to image_tag or image_url and it was working. Thanks!
这篇关于未提供Rails Cloudfront资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!