From 9ded0f3c420350144a9d41ccee3dc4b7ad9d8813 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Wed, 14 Feb 2018 10:33:30 -0500 Subject: Create ASt::Attachment records for ASt::Blobs in content --- lib/active_text/attribute.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/active_text/attribute.rb') diff --git a/lib/active_text/attribute.rb b/lib/active_text/attribute.rb index 577adde83a..9d872a87a1 100644 --- a/lib/active_text/attribute.rb +++ b/lib/active_text/attribute.rb @@ -5,6 +5,13 @@ module ActiveText class_methods do def active_text_attribute(attribute_name) serialize(attribute_name, ActiveText::Content) + + has_many_attached "#{attribute_name}_attachments" + + after_save do + blobs = public_send(attribute_name).attachments.map(&:attachable) + public_send("#{attribute_name}_attachments_blobs=", blobs) + end end end end -- cgit v1.2.3