ruby on rails - Use AWS s3 image_url for production and development -
upload images through admin feature on production. use pg_restore
pull down production database local db. problem image links broken in development. dev environment use aws s3 image urls both production , development.
looking inside consoles, see this:
local rails console
$ image.last.photo.url $ "/assets/products/3/product/__35.jpg?1415467267"
heroku console
$ image.last.photo.url $ "https://s3.amazonaws.com/app_name/app/public/assets/products/3/product/__35.jpg?1415467267"
i'm using following relevant gems: paperclip, asset_sync, , rmagick
my image class using paperclip storage:
has_attached_file :photo, paperclip_storage_opts
the storage options same in development.rb , production.rb
paperclip_storage_opts = { :styles => {:mini => '48x48>', :small => '100x100>', :medium => '200x200>', :product => '320x320>', :large => '600x600>' }, :default_style => :product, :url => "/assets/products/:id/:style/:basename.:extension", :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension" }
posted question , figured out. felt should share, in case else comes across same issue.
in config/environments/production.rb
had:
config.after_initialize paperclip::attachment.default_options[:storage] = :s3 end
the above code should added config/environments/development.rb
also!
now edit image :path
in same development.rb
file app
instead of :rails_root
:
paperclip_storage_opts = { # :styles, :default_style, , :url same above :path => "app/public/assets/products/:id/:style/:basename.:extension" }
Comments
Post a Comment