Created
August 5, 2009 17:04
-
-
Save russ/162818 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'sinatra' | |
require 'mongomapper' | |
MongoMapper.database = 'test' | |
class Property | |
include MongoMapper::Document | |
many :addresses | |
key :title, String, :required => true | |
key :price, Integer, :required => true | |
end | |
class Address | |
include MongoMapper::EmbeddedDocument | |
key :address, String, :required => true | |
key :city, String, :required => true | |
key :state, String, :required => true | |
key :postal_code, String, :required => true | |
end | |
get '/' do | |
Property.find(:all).inspect | |
end | |
get '/create' do | |
property = Property.new( | |
:title => 'Property', | |
:price => 1000000) | |
property.addresses << Address.new( | |
:address => '1234 Magic Lane', | |
:city => 'Las Vegas', | |
:state => 'NV', | |
:postal_code => '89178') | |
property.save | |
property.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment