-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
67 lines (57 loc) · 1.23 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'sinatra'
require 'sinatra/reloader'
require 'slim'
require 'sass'
require './game_routes'
require './games'
require './values_checker'
get('/styles.css'){ scss :styles }
get '/' do
@title = "Game Collection"
slim :home
end
get '/about' do
@title = "About this website"
slim :about
end
get '/contact' do
slim :contact
end
get '/new' do
@game = Games.new
slim :new_edit_game
end
#route handlers order is important... they got to stay in one file
not_found do
slim :not_found
end
get '/:console' do
@games = Games.where(console: params[:console])
slim :games_list
end
get '/:console/:id' do
@game = Games[params[:id]]
slim :game_details
end
post '/new' do
ValuesChecker.reset
ValuesChecker.right_inputs(params[:game])
unless ValuesChecker.class_variable_get(:@@inv_val).empty?
redirect '/new'
end
@new_game = Games.create(params[:game])
redirect "/#{@new_game.console}/#{@new_game[:id]}"
end
get '/:console/:id/edit' do
@game = Games[params[:id]]
slim :new_edit_game
end
put '/:console/:id' do
@game = Games[params[:id]]
@game.update(params[:game])
redirect "/#{@game.console}/#{@game.id}"
end
delete '/:console/:id' do
Games[params[:id]].destroy
redirect to("/#{params[:console]}")
end