aboutsummaryrefslogtreecommitdiffstats
path: root/actiontext/lib
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2019-03-23 10:04:48 -0400
committerGeorge Claghorn <george@basecamp.com>2019-03-23 10:04:48 -0400
commitff7948b1c2cbdf5527e40e60a4f2ef7621445d55 (patch)
tree32a7884e5fc7a4faf3fb6f563afa757a04e3b6ef /actiontext/lib
parent3acf5f71f0a8bbb8d6b2601810f4face5f9291ee (diff)
downloadrails-ff7948b1c2cbdf5527e40e60a4f2ef7621445d55.tar.gz
rails-ff7948b1c2cbdf5527e40e60a4f2ef7621445d55.tar.bz2
rails-ff7948b1c2cbdf5527e40e60a4f2ef7621445d55.zip
Avoid creating ActionText::RichText records unnecessarily
Assigning a has_one association for a persisted record saves the change immediately, so attempting to read a rich-text attribute on a persisted record without a corresponding ActionText::RichText would eagerly create one. Avoid assigning the rich text association to fix.
Diffstat (limited to 'actiontext/lib')
-rw-r--r--actiontext/lib/action_text/attribute.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/actiontext/lib/action_text/attribute.rb b/actiontext/lib/action_text/attribute.rb
index f9a604096c..ddc6822a4c 100644
--- a/actiontext/lib/action_text/attribute.rb
+++ b/actiontext/lib/action_text/attribute.rb
@@ -26,7 +26,7 @@ module ActionText
def has_rich_text(name)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
- self.rich_text_#{name} ||= ActionText::RichText.new(name: "#{name}", record: self)
+ rich_text_#{name} || build_rich_text_#{name}
end
def #{name}=(body)