我有一个使用 Amazon cloudfront cdn 交付资产的 rails 3.1.0 heroku 应用程序。除了背景图像,它没有渲染之外,一切正常。检查 firebug/Yslow 显示中的请求,
GET box.png 403 Forbidden d2g4atxxxxxx.cloudfront.net 231 B 54.240.xxx.xxx:xx
图像的 url 是http://d2g4xxxxxxxx.cloudfront.net/assets/box.png
。你可以看到它不是图像没有指纹。在 application.css 我有这个background-image:url('box.png');
我试过的东西
第一次尝试
我将 .erb 附加到 application.css 并添加了background-image:url(<%=asset_path 'box.png'%>);
然后我添加了 config.action_controller.asset_host="http://mybucket_name.com.s3.amazonaws.com"
然后我做了
bundle exec rake assets:precompile
然后我切换回
config.action_controller.asset_host ="http://d2gxxxxxxx.cloudfront.net"
然后我做了
git add application.css.erb
git commit -a
git push origin master
但它没有用
第二次尝试
我将 .scss 附加到 application.css 并添加了background-image:image-url('box.png');
然后我添加了 config.action_controller.asset_host="http://mybucket_name.com.s3.amazonaws.com"
然后我做了
bundle exec rake assets:precompile
然后我切换回
config.action_controller.asset_host ="http://d2gxxxxxxx.cloudfront.net"
然后我做了
然后我添加 gem 'compass-rails'
到一个 gemfile 并创建了 compass.rb 并添加了这个
#In compass.rb
project_type = :rails
line_comments = false
generated_images_dir = "public/assets"
bundle install
git add application.css.scss compass.rb
git commit -a
git push origin master
但它也没有工作
是)我有的
宝石文件
source 'http://rubygems.org'
gem 'rails', '3.1.0.rc8'
group :development do
gem 'sqlite3'
end
gem 'geocoder'
gem "dynamic_form"
gem 'devise'
gem 'rack', '1.3.3'
gem 'execjs'
gem 'carrierwave'
gem "meta_search",'>= 1.1.0.pre'
gem "thumbs_up"
gem 'geocoder'
gem 'fog'
gem 'koala'
group :production do
gem 'pg'
gem 'therubyracer'
gem 'unicorn'
end
gem 'jquery-rails'
gem 'thin'
gem 'mongrel', '1.2.0.pre2', :group => :development
gem 'sass-rails', " ~> 3.1.0.rc"
gem 'coffee-rails', "~> 3.1.0.rc"
gem 'uglifier'
gem 'yui-compressor'
gem "asset_sync"
# gem 'compass-rails'
group :test do
# Pretty printed test output
gem 'turn', :require => false
gem 'rspec-rails'
gem "factory_girl_rails"
gem 'capybara'
gem "guard-rspec"
end
应用程序/配置/环境/production.rb
Deals::Application.configure do
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.action_controller.asset_host ="http://d2g4xxxxxx.cloudfront.net"
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.assets.css_compressor = :yui
config.assets.js_compressor = :uglifier
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
问题
我做错了什么?或者我错过了什么步骤,有人可以指导我完成这些步骤吗?我花了整整一周时间阅读不同的博客和不同的问题,但没有运气。提前致谢