-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
43 lines (35 loc) · 890 Bytes
/
app.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
require 'sinatra/base'
require_relative 'lib/bookmark.rb'
require_relative './database_connection_setup.rb'
class BookmarkManager < Sinatra::Base
enable :sessions, :method_override
get '/' do
erb(:'/bookmarks/welcome')
end
# Method for CRUD
post '/bookmarks' do
Bookmark.create(url: params[:url], title: params[:title])
redirect '/bookmarks'
end
delete '/bookmarks/:id' do
Bookmark.delete(id: params[:id])
redirect '/bookmarks'
end
patch '/bookmarks/:id' do
Bookmark.update(id: params[:id], url: params[:url], title: params[:title])
redirect('/bookmarks')
end
# End Method for CRUD
get '/bookmarks' do
@bookmarks = Bookmark.all
erb :'bookmarks/index'
end
get '/bookmarks/new' do
erb :'bookmarks/new'
end
get '/bookmarks/:id/edit' do
@bookmark = Bookmark.find(id: params[:id])
erb(:'/bookmarks/edit')
end
run! if app_file == $0
end