From ff7948b1c2cbdf5527e40e60a4f2ef7621445d55 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Sat, 23 Mar 2019 10:04:48 -0400 Subject: 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. --- actiontext/lib/action_text/attribute.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actiontext/lib') 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) -- cgit v1.2.3