From 35e21fcff9d756090d5ab16b1c5ebaa204196022 Mon Sep 17 00:00:00 2001 From: Jan Sandbrink Date: Mon, 28 Feb 2022 16:00:45 +0100 Subject: [PATCH] Fix the example for using a CDN with ActiveStorage The code example relies on proper code being extracted from the Rails source code. This bears the risk of the code being extracted becoming outdated after a change to Rails' source. This change fixes such an inconsistency that was introduced in the past. --- guides/source/active_storage_overview.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/guides/source/active_storage_overview.md b/guides/source/active_storage_overview.md index ec61daf2d0e..a0f7144f937 100644 --- a/guides/source/active_storage_overview.md +++ b/guides/source/active_storage_overview.md @@ -645,15 +645,17 @@ You should also make sure that the generated URLs use the CDN host instead of yo ```ruby # config/routes.rb direct :cdn_image do |model, options| + expires_in = options.delete(:expires_in) { ActiveStorage.urls_expire_in } + if model.respond_to?(:signed_id) route_for( :rails_service_blob_proxy, - model.signed_id, + model.signed_id(expires_in: expires_in), model.filename, options.merge(host: ENV['CDN_HOST']) ) else - signed_blob_id = model.blob.signed_id + signed_blob_id = model.blob.signed_id(expires_in: expires_in) variation_key = model.variation.key filename = model.blob.filename