aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_text/attribute.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 16:23:04 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-04-13 16:23:04 -0700
commitf1d74871e7f00e8bbde3501a759487ac8cc4c3fc (patch)
tree2f1fa680bd1e6a356256fdc59cab5a6af8d74da7 /lib/action_text/attribute.rb
parent3bc244abc1800c7617cbfbbe1dd2597053a638c9 (diff)
downloadrails-f1d74871e7f00e8bbde3501a759487ac8cc4c3fc.tar.gz
rails-f1d74871e7f00e8bbde3501a759487ac8cc4c3fc.tar.bz2
rails-f1d74871e7f00e8bbde3501a759487ac8cc4c3fc.zip
Rename from Active Text to Action Text
This is more like Action View than Active Model.
Diffstat (limited to 'lib/action_text/attribute.rb')
-rw-r--r--lib/action_text/attribute.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/action_text/attribute.rb b/lib/action_text/attribute.rb
new file mode 100644
index 0000000000..32dd1d0e3f
--- /dev/null
+++ b/lib/action_text/attribute.rb
@@ -0,0 +1,18 @@
+module ActionText
+ module Attribute
+ extend ActiveSupport::Concern
+
+ class_methods do
+ 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