Reputation: 455
I am trying to configure my Rails app to load images from a CDN in development (I already know how to do it in production). I have tried messing around with the asset pipeline a bit and have found a way to reference the external images in the same structure as the production environment. The only caveat is that all of my assets in development now have the prefix of 'images' whereas I would like to only adjust the prefix for images.
Is that possible? Is there a better way to do this?
#config/environments/development.rb:
config.assets.prefix = "/images"
config.action_controller.asset_host = Proc.new do |source|
case source
when /\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.svg/
"https://mycdn.com/"
end
end
Upvotes: 1
Views: 677
Reputation: 44880
Move the prefix
into the asset_host
:
#config/environments/development.rb:
config.action_controller.asset_host = Proc.new do |source|
case source
when /\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.svg/
"https://mycdn.com/images"
end
end
Upvotes: 2