Skip to content

Commit

Permalink
added dev backbone, jquery, underscore libs. refactored sinatra to de…
Browse files Browse the repository at this point in the history
…al with put error, now puts are silent but do not update...
  • Loading branch information
ritchiea committed Oct 15, 2012
1 parent 219cd91 commit 5fcc541
Show file tree
Hide file tree
Showing 6 changed files with 12,083 additions and 9 deletions.
10 changes: 7 additions & 3 deletions app.rb
Expand Up @@ -23,7 +23,9 @@
end

post '/admin/api/:thing' do
oid = DB.collection(params[:thing]).insert(JSON.parse(request.body.read.to_s))
json = JSON.parse(request.body.read.to_s)
logger.info json
oid = DB.collection(params[:thing]).insert(json)
"{\"_id\": \"#{oid.to_s}\"}"
end

Expand All @@ -32,7 +34,9 @@
end

put '/admin/api/:thing/:id' do
DB.collection(params[:thing]).update({'_id' => to_bson_id(params[:id])}, {'$set' => JSON.parse(request.body.read.to_s).reject{|k,v| k == '_id'}})
json = JSON.parse(request.body.read.to_s)
logger.info json
DB.collection(params[:thing]).update({'_id' => to_bson_id(params[:id])}, json)
end

def to_bson_id(id)
Expand All @@ -41,4 +45,4 @@ def to_bson_id(id)

def from_bson_id(obj)
obj.merge({'_id' => obj['_id'].to_s})
end
end

0 comments on commit 5fcc541

Please sign in to comment.