Created
January 20, 2012 12:59
-
-
Save marvin/1647294 to your computer and use it in GitHub Desktop.
DataMapper repository issues
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 'bundler' | |
Bundler.require | |
require './dmtrouble' | |
run Sinatra::Application |
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 "bundler" | |
enable :inline_templates | |
# DataMapper | |
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/dmtrouble.db") | |
DataMapper.setup(:mongo, "mongo://localhost:27017/dmtrouble") | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.finalize | |
class Default | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
end | |
DataMapper.auto_migrate! | |
DataMapper.repository(:mongo) { | |
class Mongotest | |
include DataMapper::Mongo::Resource | |
property :id, ObjectId | |
property :name, String | |
def self.default_repository_name | |
:mongo | |
end | |
end | |
DataMapper.finalize | |
} | |
# routes | |
get "/" do | |
@defaults = Default.all | |
@mongos = Mongotest.all | |
haml :index | |
end | |
get "/adddefault" do | |
newrecord = Default.create(:name => "new test record") | |
if newrecord.save | |
redirect '/' | |
end | |
end | |
get "/addmongo" do | |
newrecord = Mongotest.create( :name => "new mongo record" ) | |
if newrecord.save | |
redirect '/' | |
end | |
end | |
__END__ | |
@@layout | |
!!! | |
%html | |
%head | |
%title "datamapper trouble" | |
%body | |
#content= yield | |
@@index | |
%h1 default data | |
- if @defaults.empty? | |
%p no data | |
- else | |
- @defaults.each do |default| | |
%p= default.name | |
%h1 mongo data_mapper | |
- if @mongos.empty? | |
%p no data | |
- else | |
- @mongos.each do |mongo| | |
%p= mongo.name |
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
source "http://rubygems.org" | |
gem 'sinatra', '~> 1.3.2', :require => 'sinatra' | |
gem 'data_mapper', '~> 1.2.0' | |
gem 'dm-mongo-adapter', :git => 'https://github.com/solnic/dm-mongo-adapter.git', :branch => "dm-1.2-compatible" | |
gem 'bson_ext', '~> 1.4.0' | |
gem 'mongo', '~> 1.4.0' | |
gem 'mongodb', '~> 2.0.0' | |
gem 'dm-sqlite-adapter' | |
gem 'haml' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you need bundle for this example!