-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.rb
49 lines (39 loc) · 1 KB
/
server.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
require 'sinatra'
require 'sinatra/activerecord'
set :views, File.join(File.dirname(__FILE__), 'app/views')
require_relative 'app/models/television_show'
get '/' do
redirect '/television_shows'
end
get '/television_shows' do
shows = TelevisionShow.all
erb :index, locals: { shows: shows }
end
get '/television_shows/new' do
show = TelevisionShow.new
erb :new, locals: { show: show }
end
get '/television_shows/:id' do
show = TelevisionShow.find(params[:id])
erb :show, locals: { show: show }
end
get '/television_shows/edit/:id' do
show = TelevisionShow.find(params[:id])
erb :edit, locals: { show: show }
end
post '/television_shows/:id' do
show = TelevisionShow.update(params[:id], params[:television_show])
if show.save
redirect '/television_shows'
else
erb :edit, locals: { show: show }
end
end
post '/television_shows' do
show = TelevisionShow.new(params[:television_show])
if show.save
redirect '/television_shows'
else
erb :new, locals: { show: show }
end
end