-
Notifications
You must be signed in to change notification settings - Fork 13
/
profiles_controller.rb
66 lines (55 loc) · 1.71 KB
/
profiles_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class ProfilesController < ApplicationController
load_and_authorize_resource
before_action :set_profile, only: [:show, :edit, :update, :destroy]
# GET /profiles/1
def show
end
# GET /profiles/new
def new
existing_profile = Profile.find_by(user: current_user.id)
return redirect_to existing_profile if existing_profile.present?
@profile = Profile.new
flash.keep(:event_id)
end
# GET /profiles/1/edit
def edit
flash.keep(:application_id)
end
# POST /profiles
def create
@profile = Profile.new(profile_params)
@profile.user_id = current_user.id
existing_profile = Profile.find_by(user: current_user.id)
return redirect_to existing_profile if existing_profile.present?
if @profile.save
if flash[:event_id]
redirect_to new_application_letter_path(:event_id => flash[:event_id]), notice: I18n.t('profiles.successful_creation')
else
redirect_to edit_user_registration_path, notice: I18n.t('profiles.successful_creation')
end
else
render :new
end
end
# PATCH/PUT /profiles/1
def update
if @profile.update(profile_params)
if flash[:application_id]
redirect_to check_application_letter_path(flash[:application_id]), notice: I18n.t('profiles.successful_update')
else
redirect_to @profile, notice: I18n.t('profiles.successful_update')
end
else
render :edit
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_profile
@profile = Profile.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def profile_params
params.require(:profile).permit(Profile.allowed_params)
end
end