diff options
Diffstat (limited to 'actiontext/lib/action_text/attribute.rb')
-rw-r--r-- | actiontext/lib/action_text/attribute.rb | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/actiontext/lib/action_text/attribute.rb b/actiontext/lib/action_text/attribute.rb index f226dd21bd..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) @@ -34,14 +34,11 @@ module ActionText end CODE - has_one :"rich_text_#{name}", -> { where(name: name) }, class_name: "ActionText::RichText", as: :record, inverse_of: :record, dependent: :destroy + has_one :"rich_text_#{name}", -> { where(name: name) }, + class_name: "ActionText::RichText", as: :record, inverse_of: :record, autosave: true, dependent: :destroy scope :"with_rich_text_#{name}", -> { includes("rich_text_#{name}") } scope :"with_rich_text_#{name}_and_embeds", -> { includes("rich_text_#{name}": { embeds_attachments: :blob }) } - - after_save do - public_send(name).save if public_send(name).changed? - end end end end |