Created
November 20, 2012 19:54
-
-
Save speric/4120598 to your computer and use it in GitHub Desktop.
Multisite Shop Example w/MongoDB
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
# 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