Support

Find answers, guides, and tutorials to supercharge your content delivery.

Ruby on Rails CDN Integration

Updated on October 4, 2018

This guide shows how to complete a Ruby on Rails (RoR) CDN integration.

  1. Create a Pull Zone or a Push Zone before you start with the RoR CDN integration.

  2. To set your asset host in Rails, you need to change config.action_controller.asset_host in config/production.rb:

    config.action_controller.asset_host = 'example-hexid.kxcdn.com'
    

    there is no need to specify the scheme (http:// or https://) in the config file. It's also possible to work with CNAMEs (e.g. cdn.yourdomain.com). In that case a Zone Alias needs to be created as well.

  3. You can also set this value through an environment variable in order to make running a staging copy of your site easier.

    config.action_controller.asset_host = ENV['CDN_HOST']
    

    For this to work, CDN_HOST needs to be set on your server (pointing to your Zone e.g. example-hexid.kxcdn.com).

  4. Once you have configured your server. Content can be delivered from KeyCDN like this:

    <%= asset_path('file.png') %>
    

    Instead of returning a path such as /assets/file.png. The URL generated will have the full path to your KeyCDN Zone such as http://example-hexid.kxcdn.com/assets/smile.png.

That's it! Your Ruby on Rails CDN integration is completed. Let us know if you have questions or issues.

Supercharge your content delivery 🚀

Try KeyCDN with a free 14 day trial, no credit card required.

Get started
KeyCDN uses cookies to make its website easier to use. Learn more