【发布时间】:2013-07-09 06:32:45
【问题描述】:
我有一个 Rails 项目,托管在 Heroku 上,我刚刚将我的资产托管转移到了 S3。除了一些自定义字体(来自 icomoon 的 SVG 字体)之外,这一切都很顺利。它们不工作,当我查看我的网络源时,我可以看到我的 S3 存储桶没有显示:
@font-face{font-family:'Starter-Icons';src:url(https://.s3.amazonaws.com/fonts/Starter-Icons.eot);src:url(https://.s3.amazonaws.com/fonts/Starter-Icons.eot?#iefix)
等等。但是,使用 S3 托管的其他资产(图像、样式表等)确实包含正确的存储桶名称。
我的 font-face 声明位于 .less 文件中(这不需要是 .less.erb 文件吗?)
@font-face {
font-family: 'Starter-Icons';
src:font-url("Starter-Icons.eot");
src:font-url("Starter-Icons.eot?#iefix") format('embedded-opentype'),
font-url("Starter-Icons.woff") format('woff'),
font-url("Starter-Icons.ttf") format('truetype'),
font-url("Starter-Icons.svg#Starter-Icons") format('svg');
font-weight: normal;
font-style: normal;
}
我所有的字体都在/app/assets/fonts。我已经按照the accepted answer here 中的步骤进行操作,但是我的存储桶名称没有显示在字体中这一事实让我相信这是一个不同的问题。
编辑
我为此使用了asset_sync gem,它的配置如下:
if defined?(AssetSync)
AssetSync.configure do |config|
config.fog_provider = 'AWS'
config.fog_directory = 'starterapp'
config.aws_access_key_id = ENV['STARTER_AWS_ACCESS_KEY_ID']
config.aws_secret_access_key = ENV['STARTER_AWS_SECRET_ACCESS_KEY']
# Don't delete files from the store
config.existing_remote_files = 'keep'
# Automatically replace files with their equivalent gzip compressed version
config.gzip_compression = true
end
结束
【问题讨论】:
-
编译后是否使用任何gem将资产放入S3?你能附上它的配置吗?文件是否在存储桶中?
-
是的,正在更新问题。文件在存储桶中(但它们不在子文件夹中——所有字体、css、js 都在我在配置中指定的主存储桶中)
-
如果您使用asset-url helper(不确定名称)?
-
是的,字体助手是
font-url,它完美地构建了它,除了存储桶名称。image_tag和其他资产助手确实获取存储桶名称。因此,图像、样式表、脚本标签等都使用asset-url 助手并且工作正常。font-url是个棘手的问题。 -
找到这个帖子,可能有用stackoverflow.com/questions/10905905/…
标签: ruby-on-rails amazon-s3 asset-pipeline