aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_text/attribute.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 16:47:33 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 16:47:33 -0700
commit7daa8cc63e1966e4cf677c4162856da896965449 (patch)
tree863565daa17a31f058070b889815e78b41147086 /lib/action_text/attribute.rb
parent421b185dab403b44216147dbca4964a52241e531 (diff)
downloadrails-7daa8cc63e1966e4cf677c4162856da896965449.tar.gz
rails-7daa8cc63e1966e4cf677c4162856da896965449.tar.bz2
rails-7daa8cc63e1966e4cf677c4162856da896965449.zip
WIP
Diffstat (limited to 'lib/action_text/attribute.rb')
-rw-r--r--lib/action_text/attribute.rb31
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/action_text/attribute.rb b/lib/action_text/attribute.rb
index 32dd1d0e3f..bd76999167 100644
--- a/lib/action_text/attribute.rb
+++ b/lib/action_text/attribute.rb
@@ -3,16 +3,33 @@ module ActionText
extend ActiveSupport::Concern
class_methods do
- def has_rich_text(attribute_name)
- serialize(attribute_name, ActionText::Content)
+ def has_rich_text(name)
+ class_eval <<-CODE, __FILE__, __LINE__ + 1
+ def #{name}
+ rich_text_#{name}
+ end
- has_many_attached "#{attribute_name}_attachments"
+ def #{name}=(body)
+ #{name}.body = body
+ end
+ CODE
- after_save do
- blobs = public_send(attribute_name).attachments.map(&:attachable)
- public_send("#{attribute_name}_attachments_blobs=", blobs)
- end
+ has_one :"rich_text_#{name}", -> { where(name: name) }, class_name: "ActionText::RichText", as: :record, inverse_of: :record, dependent: false
+
+ scope :"with_rich_text_#{name}", -> { includes("rich_text_#{name}") }
end
+
+
+ # def has_rich_text(attribute_name)
+ # serialize(attribute_name, ActionText::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
end