From d15abe14d14ec69fe8562f07f4480c5e3156828f Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 18 Sep 2020 17:46:25 +0100 Subject: [PATCH] Join reformat styles and set attachement definitions and explain why we need to run them every time Spree::Image is loaded although this is also done in the spree initializer --- app/models/spree/image.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/spree/image.rb b/app/models/spree/image.rb index 10d09fb02f..cb14265f14 100644 --- a/app/models/spree/image.rb +++ b/app/models/spree/image.rb @@ -20,8 +20,6 @@ module Spree include Spree::Core::S3Support supports_s3 :attachment - Spree::Image.set_attachment_definitions - # used by admin products autocomplete def mini_url attachment.url(:mini, false) @@ -59,7 +57,7 @@ module Spree if Spree::Config[:use_s3] s3_creds = { access_key_id: Spree::Config[:s3_access_key], secret_access_key: Spree::Config[:s3_secret], - bucket: Spree::Config[:s3_bucket]} + bucket: Spree::Config[:s3_bucket] } Spree::Image.attachment_definitions[:attachment][:storage] = :s3 Spree::Image.attachment_definitions[:attachment][:s3_credentials] = s3_creds Spree::Image.attachment_definitions[:attachment][:s3_headers] = @@ -90,6 +88,9 @@ module Spree format_styles(Spree::Image.attachment_definitions[:attachment][:styles]) end + # We need to run this every time Spree::Image is loaded because "has_attached_file :attachment" + # is setting default values that are not the ones coming from Spree::Config + set_attachment_definitions reformat_styles end end