Skip to content

Instantly share code, notes, and snippets.

@russ
Created August 5, 2009 17:04
Show Gist options
  • Save russ/162818 to your computer and use it in GitHub Desktop.
Save russ/162818 to your computer and use it in GitHub Desktop.
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