Search code examples
ruby-on-railsrails-activestorageruby-on-rails-6

Configure CDN for Rails 6 ActiveStorage


I have configured ActiveStorage and it works properly.

However I need to change the final URLs returned to the users, so that they use a CDN.

Currently the final image URL is:

https://mywebsite.nyc1.digitaloceanspaces.com/...

But I need this instead:

https://mywebsite.nyc1.cdn.digitaloceanspaces.com/...

Is it possible to achieve that in Rails 6?


Solution

  • It seems not possible to configure Rails 6.0 to use a CDN at the moment... However I was able to achieve that by using:

    variant.service_url.sub('digitaloceanspaces.com', 'cdn.digitaloceanspaces.com')