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.
13 lines
287 B
Ruby
13 lines
287 B
Ruby
module Imageable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_one :image, as: :imageable, dependent: :destroy
|
|
accepts_nested_attributes_for :image, allow_destroy: true, update_only: true
|
|
|
|
def image_url(style)
|
|
image&.attachment&.url(style) || ""
|
|
end
|
|
end
|
|
end
|