-
Notifications
You must be signed in to change notification settings - Fork 2
/
user_resumes_controller.rb
45 lines (37 loc) · 1023 Bytes
/
user_resumes_controller.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
class UserResumesController < ApplicationController
before_action :set_user_and_resume
respond_to :html
layout 'users'
def new
if @user_resume.present?
redirect_to edit_users_resume_path
else
@user_resume = UserResume.new(user_id: @user.id)
end
end
def edit
unless @user_resume.present?
redirect_to new_users_resume_path
end
end
def create
@user_resume = UserResume.new(user_id: @user.id, body: user_resume_params[:body])
@user_resume.save
flash[:notice] = 'Resume created.'
redirect_to home_path(@user.nick)
end
def update
@user_resume.update_body(user_resume_params[:body])
flash[:notice] = 'Resume updated.'
redirect_to home_path(@user.nick)
end
private
def set_user_and_resume
redirect_to(root_path) and return unless view_context.myself?(current_user)
@user = current_user
@user_resume = current_user.resume
end
def user_resume_params
params.require(:user_resume).permit(:user_id, :body)
end
end