1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/lib/action_text/attribute.rb
David Heinemeier Hansson 7daa8cc63e WIP
2018-04-13 16:47:33 -07:00

35 lines
966 B
Ruby

module ActionText
module Attribute
extend ActiveSupport::Concern
class_methods do
def has_rich_text(name)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
rich_text_#{name}
end
def #{name}=(body)
#{name}.body = body
end
CODE
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