Skip to content

Instantly share code, notes, and snippets.

@speric
Created November 20, 2012 19:54
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 speric/4120598 to your computer and use it in GitHub Desktop.
Save speric/4120598 to your computer and use it in GitHub Desktop.
Multisite Shop Example w/MongoDB
# Order class
# see http://www.slideshare.net/wonko/persisting-dynamic-data-with-mongodb-and-mongomapper
class Order
include MongoMapper::Document
key :order_id, String
class << self
def for_site(site)
klass = Class.new(self)
klass.order_fields = site.order_fields
Object.const_set("OrderForSite#{site.id}", klass)
klass
end
def order_fields=(fields)
fields.each do |field|
key field, String
end
end
end
end
# current_site.order_fields
# => ["field1", "field2"]
# @order = Order.for_site(current_site).new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment