3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/action_markdown/attribute.rb', line 3
def has_markdown(name)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
markdown_#{name} || build_markdown_#{name}
end
def #{name}=(body)
self.#{name}.body = body
end
CODE
has_one :"markdown_#{name}", -> { where(name: name) }, class_name: "ActionMarkdown::MarkdownText",
as: :record, inverse_of: :record, autosave: true, dependent: :destroy
scope :"with_markdown_#{name}", -> { includes("markdown_#{name}") }
end
|