Skip to content

Instantly share code, notes, and snippets.

@jacqui
Created June 3, 2010 13:58
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacqui/423921 to your computer and use it in GitHub Desktop.
Save jacqui/423921 to your computer and use it in GitHub Desktop.
Using embedded documents to store field data
class Field
include MongoMapper::EmbeddedDocument
key :name, String
key :label, String, :required => true
key :helper_text, String
key :required, Boolean, :default => false
key :widget, String, :required => true
key :options, Array # => [[value, label], [value, label], [value, label]]
key :selected, String
key :word_limit, Integer, :default => 0
key :position, Integer, :default => 0
key :form_id, BSON::ObjectID
belongs_to :form
end
class Form
include MongoMapper::Document
key :name, String, :required => true, :unique => true
# additional fields for the form...
many :fields, :order => 'position'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment