问题
I am using paperclip + AWS in my rails app to upload images.
When I reference images in my view as
<%= image_tag product.avatar.url(:medium) %>
current image urls are showing up as:
http://s3.amazonaws.com/rockywolfugc/products/avatars/000/000/003/medium/59577_10100258833612183_1508749_n.jpg?1386876682
I need them to show up as:
http://rockywolfugc.s3-us-west-2.amazonaws.com/products/avatars/000/000/003/medium/59577_10100258833612183_1508749_n.jpg?1386876682
At http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3 I'm seeing there is an option for ":s3_domain_url" but I'm not quite sure how to use it.
Below is the relevant portion of production.rb
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
Where do I integrate the s3_domain_url in this file? Additionally, what do I have to do on heroku to get this to run? Example: heroku config:set xxxx=yyyy
回答1:
try setting
config.action_controller.asset_host = "//#{ENV['AWS_BUCKET_NAME']}.s3-us-west-2.amazonaws.com"
in your production.rb
来源:https://stackoverflow.com/questions/20558281/how-to-edit-production-rb-in-my-rails-app-to-get-it-working-using-heroku-and-pap