Skip to content

Instantly share code, notes, and snippets.

@yknd
Created February 1, 2012 02:59
Show Gist options
  • Save yknd/1714812 to your computer and use it in GitHub Desktop.
Save yknd/1714812 to your computer and use it in GitHub Desktop.
sample sinatra mongodb
require 'bundler/setup'
require 'json'
Bundler.require(:default)
class Thing
include Mongoid::Document
field :x, type: Integer
field :j, type: Integer
end
class MyApp < Sinatra::Base
configure :development do
register Sinatra::Reloader
end
configure do
Mongoid.load!("mongoid.yml")
end
get '/things.json' do
content_type :json
all_things = Thing.all
all_things.to_json
end
end
require 'bundler'
Bundler.require
require './app'
run MyApp
source :rubygems
gem 'sinatra', require: 'sinatra/base'
gem 'sinatra-reloader', require: 'sinatra/reloader'
gem 'mongoid'
gem 'bson_ext'
gem 'thin'
GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.1)
activesupport (= 3.2.1)
builder (~> 3.0.0)
activesupport (3.2.1)
i18n (~> 0.6)
multi_json (~> 1.0)
backports (2.3.0)
bson (1.5.2)
bson_ext (1.5.2)
bson (= 1.5.2)
builder (3.0.0)
daemons (1.1.6)
eventmachine (0.12.10)
i18n (0.6.0)
mongo (1.5.2)
bson (= 1.5.2)
mongoid (2.4.3)
activemodel (~> 3.1)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
multi_json (1.0.4)
rack (1.4.1)
rack-protection (1.2.0)
rack
rack-test (0.6.1)
rack (>= 1.0)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
sinatra-contrib (1.3.1)
backports (>= 2.0)
eventmachine
rack-protection
rack-test
sinatra (~> 1.3.0)
tilt (~> 1.3)
sinatra-reloader (1.0)
sinatra-contrib
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
tzinfo (0.3.31)
PLATFORMS
ruby
DEPENDENCIES
bson_ext
mongoid
sinatra
sinatra-reloader
thin
development:
host: localhost
database: mydb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment