-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.rb
84 lines (74 loc) · 1.51 KB
/
controller.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
78
79
80
81
82
83
84
require 'sinatra'
require_relative './database.rb'
#Main redirect:
get '/' do
redirect '/students'
end
#index:
get '/students' do
db = DBHandler.new
@all_students = db.all
@all_enrolled = db.all_enrolled
@all_graduated = db.all_graduated
erb :application do
erb :index
end
end
get '/students/enrolled' do
db = DBHandler.new
@all_enrolled = db.all_enrolled
erb :application do
erb :index
end
end
get '/students/graduated' do
db = DBHandler.new
@all_graduated = db.all_graduated
erb :application do
erb :index
end
end
#new:
get '/students/new' do
erb :application do
erb :new
end
end
#create:
post '/students' do
db = DBHandler.new
db.create(params[:fname], params[:lname], params[:email], params[:major], params[:status])
redirect to '/students'
end
#show:
get '/students/:id' do
id = params[:id].to_i
db = DBHandler.new
@student_item = db.get(id)
erb :application do
erb :show
end
end
#edit:
get '/students/:id/edit' do
id = params[:id].to_i
db = DBHandler.new
@student_item = db.get(id)
erb :application do
erb :edit
end
end
#update:
patch '/students/:id' do
id = params[:id].to_i
db = DBHandler.new
db.update(id, params[:fname], params[:lname], params[:email], params[:major], params[:status])
redirect to '/students'
end
#delete:
get '/students/:id/delete' do
id = params[:id].to_i
db = DBHandler.new
db.destroy(id)
redirect to '/students'
end