-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
77 lines (61 loc) · 1.58 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'sinatra'
require 'data_mapper'
require 'dm-migrations'
configure do
set :datastore, DataMapper.setup(:default, 'sqlite::memory:')
end
class Event
include DataMapper::Resource
property :id, Serial # An auto-increment integer key
property :start, DateTime # A varchar type string, for short strings
property :duration, Integer # Minutes for the event
property :body, Text # A text block, for longer string data.
property :created_at, DateTime # A DateTime, for any date you might like.
end
DataMapper.finalize
DataMapper.auto_upgrade!
Event.create({start: Time.now, duration: 10, body: "HEY"})
get '/date' do
Time.now.to_s
end
get '/' do
haml :index
end
get '/events' do
@events = Event.all
haml :index
end
get '/event/new' do
haml :new
end
get '/event/edit/:id' do
@event = Event.get(params[:id])
haml :edit
end
post '/event/update' do
start = params[:start]
duration = params[:duration]
body = params[:body]
puts params.inspect
event = Event.get(params[:id])
event.update({start: start, duration: duration.to_i, body: body})
redirect to("/event/#{event.id}")
end
get '/event/:id' do
@event = Event.get(params[:id])
haml :show
end
post '/event/create' do
start = params[:start]
duration = params[:duration]
body = params[:body]
event = Event.create({start: start, duration: duration.to_i, body: body})
redirect to("/event/#{event.id}")
end
#Prints routes
Sinatra::Application.routes.each do |route|
puts "VERB: #{route[0]}"
route[1].each do |p|
puts "\tPATH: #{p[0]} Params: #{p[1]}"
end
end