-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlinkedout.rb
113 lines (88 loc) · 1.87 KB
/
linkedout.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'sinatra'
require 'sinatra/partial'
require 'better_errors'
require_relative 'config/dotenv'
require_relative 'models'
set :partial_template_engine, :erb
configure :development do
use BetterErrors::Middleware
BetterErrors.application_root = File.expand_path('..', __FILE__)
end
helpers do
def default_user
@default_user ||= User.last
end
end
get "/" do
@jobs = default_user.jobs
@skills = default_user.skills
erb :'resumes/show'
end
get "/users/edit" do
erb :'users/edit'
end
put "/users/edit" do
user_attrs = params[:user]
default_user.update(user_attrs)
redirect "/"
end
post "/jobs" do
job_attrs = params[:job]
job_attrs.merge!({ :user => default_user })
job = Job.new(job_attrs)
job.save
if request.xhr?
html = "<li>"
html += partial :'partials/job', :locals => { :job => job }
html += partial :'partials/job_edit', :locals => { :job => job }
html += "</li>"
html
else
redirect "/"
end
end
put "/jobs/:job_id" do
job_id = params[:job_id]
job_attrs = params[:job]
job = Job.get(job_id)
job.update(job_attrs)
if request.xhr?
partial :'partials/job', :locals => { :job => job }
else
redirect "/"
end
end
delete "/jobs/:job_id" do
job_id = params[:job_id]
job = Job.get(job_id)
job.destroy
if request.xhr?
job_id
else
redirect "/"
end
end
post "/skills" do
skill_attrs = params[:skill]
skill_attrs.merge!({ :user => default_user })
skill = Skill.new(skill_attrs)
skill.save
if request.xhr? # this will return true when handling an AJAX request
html = "<li>"
html += partial :'partials/skill', :locals => { :skill => skill }
html += "</li>"
html
else
redirect "/"
end
end
delete "/skills/:skill_id" do
skill_id = params[:skill_id]
skill = Skill.get(skill_id)
skill.destroy
if request.xhr?
skill_id
else
redirect "/"
end
end