Created
August 14, 2012 00:56
-
-
Save wheeyls/3345278 to your computer and use it in GitHub Desktop.
Document/Paragraph Data Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_paragraphs(paragraphs_attrs) | |
paragraphs_attrs.select do |key, value| | |
# make changes and filter out existing attributes | |
end | |
end | |
def assign_attributes(attr, options = {}) | |
paragraphs_attrs = attr.delete :paragraphs_attributes | |
# manually update any existing paragraphs here | |
paragraphs_attrs = process_paragraphs(paragraphs_attrs) | |
# pass any new paragraphs onto super | |
attr.merge!(paragraphs_attributes: paragraphs_attrs) if paragraphs_attrs | |
super(attr, options) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DocInstance | |
belongs_to :doc_template | |
has_many :paragraph_instances | |
end | |
class ParagraphInstance | |
belongs_to :doc_instance | |
belongs_to :paragraph_template | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DocTemplate | |
has_many :sections | |
has_many :doc_instances | |
end | |
class Section | |
has_many :paragraphs | |
end | |
class ParagraphTemplate | |
belongs_to :section | |
has_many :paragraph_instances | |
attr_accessor :max_length, :required, :title | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment