-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathchapter_controller.rb
More file actions
36 lines (28 loc) · 1.03 KB
/
chapter_controller.rb
File metadata and controls
36 lines (28 loc) · 1.03 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
class ChapterController < ApplicationController
include AttendanceConcerns
def show
@chapter = ChapterPresenter.new(Chapter.active.find_by!(slug: slug))
upcoming_workshops = upcoming_events_by_chapter(@chapter)
@upcoming_workshops = event_presenters_by_date(upcoming_workshops)
past_event = @chapter.workshops.most_recent
past_events = past_event.present? ? [past_event].group_by(&:date) : []
@latest_workshops = event_presenters_by_date(past_events)
@recent_sponsors = Sponsor.recent_for_chapter(@chapter)
@attending_ids = attending_workshops
end
private
def slug
params.permit(:id)[:id]
end
def upcoming_events_by_chapter(chapter)
workshops = chapter.upcoming_workshops.includes(:sponsors)
events = chapter.events.upcoming
[*workshops, *events].uniq.compact.sort_by(&:date_and_time).group_by(&:date)
end
def event_presenters_by_date(events)
events.map.inject({}) do |hash, (date, value)|
hash[date] = EventPresenter.decorate_collection(value)
hash
end
end
end