-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
51 lines (39 loc) · 813 Bytes
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'sinatra'
require 'mongo_mapper'
MongoMapper.connection = Mongo::Connection.new('staff.mongohq.com',10019, :pool_size => 5, :timeout => 5)
MongoMapper.database = 'upward'
MongoMapper.database.authenticate('rootuser','rootpassword')
class Post
include MongoMapper::Document
key :wins, String
key :lessons, String
key :goals, String
timestamps!
end
get '/' do
@posts = Post.all
erb :index
end
get '/posts' do
@posts = Post.all
erb :list
end
get '/posts/new' do
erb :new
end
post '/posts/create' do
@post = Post.new
@post.wins = (params[:wins])
@post.lessons = (params[:lessons])
@post.goals = (params[:goals])
if @post.save
status 201
else
status 401
end
redirect '/posts'
end
get '/posts/:id/edit' do
@post = Post.find(params[:id])
erb :edit
end