Skip to content

Instantly share code, notes, and snippets.

@wheeyls
Created August 14, 2012 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wheeyls/3345278 to your computer and use it in GitHub Desktop.
Save wheeyls/3345278 to your computer and use it in GitHub Desktop.
Document/Paragraph Data Model
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
class DocInstance
belongs_to :doc_template
has_many :paragraph_instances
end
class ParagraphInstance
belongs_to :doc_instance
belongs_to :paragraph_template
end
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