From c9752e94bed696f2d76f3448565ead07b045668d Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Thu, 4 Apr 2019 16:40:26 +0200 Subject: [PATCH] Change the way we retrireve the images urls For some reason the paperclip method `attachment.exists?' was returning nil even when `attachment.url(style)' was correctly returning the url/path of the attachment. Therefore returning `nil' was causing to raise an error in the method `image_tag'. With this change we make sure we return the image url it it's available, or an empty string if it's not, but never a null value. --- app/models/concerns/galleryable.rb | 4 ++-- app/models/concerns/imageable.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/galleryable.rb b/app/models/concerns/galleryable.rb index 1063c5571..5ddf322f6 100644 --- a/app/models/concerns/galleryable.rb +++ b/app/models/concerns/galleryable.rb @@ -6,7 +6,7 @@ module Galleryable accepts_nested_attributes_for :images, allow_destroy: true, update_only: true def image_url(style) - image.attachment.url(style) if image && image.attachment.exists? + image&.attachment&.url(style) || "" end end -end \ No newline at end of file +end diff --git a/app/models/concerns/imageable.rb b/app/models/concerns/imageable.rb index 727ff9a6b..3e3b15685 100644 --- a/app/models/concerns/imageable.rb +++ b/app/models/concerns/imageable.rb @@ -6,7 +6,7 @@ module Imageable accepts_nested_attributes_for :image, allow_destroy: true, update_only: true def image_url(style) - image.attachment.url(style) if image && image.attachment.exists? + image&.attachment&.url(style) || "" end end end