From 9a489adc1220628207ea38e7fdc58311e290c596 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Wed, 27 May 2020 12:05:30 -0400 Subject: [PATCH] [deploy] Fix cloudinary helper (#6701) Co-authored-by: Molly Struve --- app/helpers/application_helper.rb | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5a313beff..186fc7271 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,6 @@ module ApplicationHelper + include CloudinaryHelper + # rubocop:disable Performance/OpenStruct DELETED_USER = OpenStruct.new( id: nil, @@ -74,20 +76,15 @@ module ApplicationHelper "https://res.cloudinary.com/#{ApplicationConfig['CLOUDINARY_CLOUD_NAME']}/image/upload/#{postfix}" end - def cloudinary(url, width = nil, _quality = 80, _format = "jpg") - return url if Rails.env.development? && (url.blank? || url.exclude?("http")) - - service_path = "https://res.cloudinary.com/#{ApplicationConfig['CLOUDINARY_CLOUD_NAME']}/image/fetch" - - if url&.size&.positive? - if width - "#{service_path}/c_scale,fl_progressive,q_auto,w_#{width}/f_auto/#{url}" - else - "#{service_path}/c_scale,fl_progressive,q_auto/f_auto/#{url}" - end - else - "#{service_path}/c_scale,fl_progressive,q_1/f_auto/https://pbs.twimg.com/profile_images/481625927911092224/iAVNQXjn_normal.jpeg" - end + def cloudinary(url, width = "500", quality = 80, format = "jpg") + cl_image_path(url || asset_path("#{rand(1..40)}.png"), + type: "fetch", + width: width, + crop: "limit", + quality: quality, + flags: "progressive", + fetch_format: format, + sign_url: true) end def cloud_cover_url(url)