-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathusers_controller.rb
52 lines (40 loc) · 1.27 KB
/
users_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
# frozen_string_literal: true
class UsersController < ApplicationController
include IcalHelper
before_action :authenticate_current_user!, only: %i[edit update]
expose(:user, find: ->(id, scope) { scope.from_slug(id) })
expose(:users) { User.peers.page(params[:page]).per(3 * 10) }
def index; end
def show; end
def edit
return unless current_user.missing_name?
user.name = nil
user.errors.add(:name, :required)
end
def calendar
respond_to do |format|
format.ics do
render plain: icalendar(*user.participations)
end
end
end
def update
if current_user.update user_params
redirect_back(notice: t('user.saved_successful'), fallback_location: root_url)
else
redirect_back(alert: current_user.errors.full_messages.join(' '), fallback_location: root_url)
end
end
def destroy
if current_user.events.present?
redirect_to edit_user_path(current_user), alert: t('user.not_removed_organizer')
else
current_user.destroy
redirect_to destroy_session_path, notice: t('user.removed')
end
end
private
def user_params
params.require(:user).permit(:twitter, :github, :linkedin, :email, :name, :description, :freelancer, :available, :hide_jobs, :participants, :image, :url)
end
end