Created
November 14, 2012 20:45
-
-
Save brookemckim/4074683 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'sinatra/base' | |
require 'dm-core' | |
require 'dm-migrations' | |
require 'dm-serializer/to_json' | |
module BestAppEver | |
class App < Sinatra::Base | |
configure :development do | |
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/db/best_app_ever_development.db") | |
DataMapper::Logger.new(STDOUT, :debug) | |
end | |
DataMapper::Model.raise_on_save_failure = true | |
DataMapper.finalize | |
DataMapper.auto_upgrade! | |
get '/users' do | |
users = User.all | |
users.to_json | |
end | |
end | |
end |
This file contains hidden or 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 'dm-core' | |
require 'dm-validations' | |
require 'dm-serializer/to_json' | |
class User | |
include DataMapper::Resource | |
property :id, Serial | |
property :uid, String | |
property :token, String | |
has n, :discussions | |
def as_json(*a) | |
{ | |
id: id.to_s, | |
uid: uid, | |
token: token | |
} | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment