-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
77 lines (58 loc) · 1.12 KB
/
app.rb
File metadata and controls
77 lines (58 loc) · 1.12 KB
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 'rubygems'
require 'sinatra'
require 'data_mapper'
require 'json'
DataMapper.setup(:default, "sqlite3::memory:")
class Province
include DataMapper::Resource
property :id, Serial
property :name, String
attr_accessor :name
def initialize(name)
@name = name
end
def to_json(*)
{name: @name}.to_json
end
end
get '/' do
haml :index
end
get '/provinces' do
provinces = Province.all
content_type :json
provinces.to_json
end
get '/provinces/new' do
haml :"provinces/new"
end
post 'province' do
province = Province.create(name: params[:name])
redirect '/'
end
class IncidentType
include DataMapper::Resource
property :id, Serial
property :name, String
attr_accessor :name
def initialize(name)
@name = name
end
def to_json(*)
{name: @name}.to_json
end
end
get '/incident_types' do
incident_types = IncidentType.all
content_type :json
incident_types.to_json
end
get '/incident_types/new' do
haml :"incident_types/new"
end
post 'incident_type' do
province = IncidentType.create(name: params[:name])
redirect '/'
end
DataMapper.finalize
DataMapper.auto_upgrade!