-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
82 lines (67 loc) · 1.9 KB
/
app.rb
File metadata and controls
82 lines (67 loc) · 1.9 KB
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
require 'sinatra/base'
require 'sinatra/flash'
require 'uri'
require './lib/bookmark'
require './lib/comment'
require './lib/tag'
require './lib/bookmark_tag'
require_relative './database_connection_setup'
class BookmarkManager < Sinatra::Base
enable :sessions, :method_override
register Sinatra::Flash
configure do
# allows sinatra to find my CSS stylesheet
set :public_folder, File.expand_path('../public', __FILE__)
set :views , File.expand_path('../views', __FILE__)
set :root , File.dirname(__FILE__)
end
get '/' do
erb(:home)
end
get '/bookmarks' do
@bookmarks = Bookmark.all
erb(:'bookmarks/index')
end
post '/bookmarks' do
flash[:notice] = "You must submit a valid URL" unless Bookmark.create(url: params[:url], title: params[:title])
redirect '/bookmarks'
end
delete '/bookmarks/:id' do
Bookmark.delete(id: params[:id])
redirect('/bookmarks')
end
get '/bookmarks' do
erb(:'bookmarks')
end
get "/bookmarks/:id/edit" do
@bookmark = Bookmark.find(id: params[:id])
erb(:'bookmarks/edit')
end
patch "/bookmarks/:id" do
Bookmark.update(id: params[:id], url: params[:url], title: params[:title])
redirect('/bookmarks')
end
get "/bookmarks/:id/comments/new" do
@bookmark_id = params[:id]
erb(:'comments/new')
end
post "/bookmarks/:id/comments" do
Comment.create(text: params[:comment], bookmark_id: params[:id])
redirect '/bookmarks'
end
get "/bookmarks/:id/tags/new" do
@bookmark_id = params[:id]
erb(:'/tags/new')
end
post "/bookmarks/:id/tags" do
tag = Tag.create(content: params[:tag])
BookmarkTag.create(bookmark_id: params[:id], tag_id: tag.id)
redirect '/bookmarks'
end
get "/tags/:id/bookmarks" do
@tag = Tag.find(id: params[:id])
erb(:'/tags/index')
end
# start the server if ruby file executed directly
run! if app_file == $0
end