Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
YStrano
GitHub Repository: YStrano/DataScience_GA
Path: blob/master/april_18/templates/example-lesson/solution-code/app.rb
1904 views
1
class Tunr < Sinatra::Base
2
3
# General route actions
4
get '/' do
5
erb :home
6
end
7
8
get '/about' do
9
erb :about
10
end
11
12
# RESTful Artist Controller Actions
13
# index
14
get '/artists' do
15
@artists = Artist.all
16
erb(:"artists/index")
17
end
18
19
# new
20
get '/artists/new' do
21
@artist = Artist.new
22
erb(:"artists/new")
23
end
24
25
# create
26
post '/artists' do
27
@artist = Artist.new(params[:artist])
28
if @artist.save
29
redirect("/artists/#{@artist.id}")
30
else
31
erb(:"artists/new")
32
end
33
end
34
35
# show
36
get '/artists/:id' do
37
@artist = Artist.find(params[:id])
38
erb(:"artists/show")
39
end
40
41
# edit
42
get '/artists/:id/edit' do
43
@artist = Artist.find(params[:id])
44
erb(:"artists/edit")
45
end
46
47
# update
48
put '/artists/:id' do
49
@artist = Artist.find(params[:id])
50
if @artist.update_attributes(params[:artist])
51
redirect("/artists/#{artist.id}")
52
else
53
erb(:"artists/edit")
54
end
55
end
56
57
# delete
58
delete '/artists/:id/delete' do
59
@artist = Artist.find(params[:id])
60
if @artist.destroy
61
redirect('/artists')
62
else
63
redirect("/artists/#{@artist.id}")
64
end
65
end
66
67
end
68
69