Permalink
Browse files

examples in classic and modular style

  • Loading branch information...
1 parent 14d76c7 commit d43a2922ab3d5fec063a1cb43a59eeed95ed765f Jordan West committed Aug 15, 2010
Showing with 46 additions and 0 deletions.
  1. +22 −0 examples/classic.rb
  2. +24 −0 examples/modular.rb
View
@@ -0,0 +1,22 @@
+$: << File.join(File.dirname(__FILE__), %w/.. lib/)
+require 'sinatra'
+require 'sinatra/mongomatic'
+
+mongomatic nil
+
+class User < Mongomatic::Base
+
+end
+
+get '/create/:name' do
+ User.new(:name => params[:name]).insert
+ "ok"
+end
+
+get '/all' do
+ User.find.inject("") do |list, user|
+ list += "#{user[:name]}<br>"
+ end
+end
+
+
View
@@ -0,0 +1,24 @@
+$: << File.join(File.dirname(__FILE__), %w/.. lib/)
+require 'sinatra/base'
+require 'sinatra/mongomatic'
+
+class User < Mongomatic::Base
+end
+
+class MongomaticExample < Sinatra::Base
+ register Sinatra::Mongomatic
+
+ mongomatic nil
+
+ get '/create/:name' do
+ User.new(:name => params[:name]).insert
+ "ok"
+ end
+
+ get '/all' do
+ User.find.inject("") do |list, user|
+ list += "#{user[:name]}<br>"
+ end
+ end
+ run! if $0 == __FILE__
+end

0 comments on commit d43a292

Please sign in to comment.