Assets & IPv6 on Ruby on Rails

All of our internal production sites starting in 2009 have been launched with dual stack IPv4/IPv6 from day one.  We typically serve static assets (images and javascript) from our content delivery network to improve load performance.  Unfortunately, the CDN we use is IPv4 only. The following Ruby on Rails code snippet is from /config/environments/production.rb that rewrites static asset paths to serve from the RoR server for IPv6 and SSL requests and the CDN for IPv4 requests.

{% codeblock %}
ActionController::Base.asset_host = Proc.new { |source, request|
remote_ip = IPAddr.new(request.remote_ip)
if request.ssl? || remote_ip.ipv6?
"#{request.protocol}#{request.host_with_port}"
else

replace your.cdn/path with the host + path to your IPv4-only CDN

"#{request.protocol}your.cdn/path"
end
}
{% endcodeblock %}