about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-06-29 17:59:04 +0200
committerGitHub <noreply@github.com>2020-06-29 17:59:04 +0200
commit1b198d64890de3eed5562c9b485ed8cafbff059f (patch)
tree5263efed482fd28688a1a5bdd12dfea09c3c824d /app
parentfa183a51ab0d8c8bbacd2d5e7474cd2bc9c9000c (diff)
Fix trying to write non-existent image remote URL attribute on preview cards (#14181)
Regression from #14145
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/remotable.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/app/models/concerns/remotable.rb b/app/models/concerns/remotable.rb
index 6fc1dcc26..53ebc0835 100644
--- a/app/models/concerns/remotable.rb
+++ b/app/models/concerns/remotable.rb
@@ -7,8 +7,8 @@ module Remotable
     def remotable_attachment(attachment_name, limit, suppress_errors: true, download_on_assign: true, attribute_name: nil)
       attribute_name ||= "#{attachment_name}_remote_url".to_sym
 
-      define_method("download_#{attachment_name}!") do
-        url = self[attribute_name]
+      define_method("download_#{attachment_name}!") do |url = nil|
+        url ||= self[attribute_name]
 
         return if url.blank?
 
@@ -51,9 +51,9 @@ module Remotable
       define_method("#{attribute_name}=") do |url|
         return if self[attribute_name] == url && public_send("#{attachment_name}_file_name").present?
 
-        self[attribute_name] = url
+        self[attribute_name] = url if has_attribute?(attribute_name)
 
-        public_send("download_#{attachment_name}!") if download_on_assign
+        public_send("download_#{attachment_name}!", url) if download_on_assign
       end
 
       alias_method("reset_#{attachment_name}!", "download_#{attachment_name}!")