From 45a2e0de8e1e758586e311d1d9c7e3a8a69c318b Mon Sep 17 00:00:00 2001 From: Tom Close Date: Tue, 6 Aug 2013 10:13:59 +0100 Subject: [PATCH] Initial import --- Gemfile | 3 +++ app.rb | 32 ++++++++++++++++++++++++++++++++ db_examples.rb | 26 ++++++++++++++++++++++++++ mongoid.yml | 6 ++++++ 4 files changed, 67 insertions(+) create mode 100644 Gemfile create mode 100644 app.rb create mode 100644 db_examples.rb create mode 100644 mongoid.yml diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..ed07d3a --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' +ruby '1.9.3' +gem 'mongoid' diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..ae0860a --- /dev/null +++ b/app.rb @@ -0,0 +1,32 @@ +require 'sinatra' +require 'mongoid' +require 'json' + +## Mongoid setup +## ============= + +Mongoid.load!("mongoid.yml", :development) + +class User + include Mongoid::Document + + field :name + field :email +end + +## Sinatra app +## =========== + +# display form +get '/' do + +end + +# add new user, display thanks +post '/' do + +end + +# show all the users so far +get '/list' do +end \ No newline at end of file diff --git a/db_examples.rb b/db_examples.rb new file mode 100644 index 0000000..0372fdf --- /dev/null +++ b/db_examples.rb @@ -0,0 +1,26 @@ +require 'mongoid' +require 'json' + +Mongoid.load!("mongoid.yml", :development) + +class User + include Mongoid::Document + + field :name + field :email +end + + +# How many users are there currently in the database +User.count + + +u = User.new(:name => "Tom", :email => 'tom@example.com') + +u.save + +u1 = User.first + +User.count + +User.all {|u| puts u.name} \ No newline at end of file diff --git a/mongoid.yml b/mongoid.yml new file mode 100644 index 0000000..5544c65 --- /dev/null +++ b/mongoid.yml @@ -0,0 +1,6 @@ +development: + sessions: + default: + hosts: + - localhost:27017 + database: mongo_examples \ No newline at end of file