Verified Commit 39bc9a2e authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

feat(semester-process): run builders in controller and filter selected volunter ids from form data

parent e2ff194e
......@@ -10,7 +10,8 @@ class SemesterProcessesController < ApplicationController
def show; end
def new
@semester_process = SemesterProcess.new
@semester_process = SemesterProcess.new(semester: @selected_semester)
@semester_process.build_semester_volunteers(@volunteers)
authorize @semester_process
end
......@@ -19,6 +20,8 @@ class SemesterProcessesController < ApplicationController
def create
@semester_process = SemesterProcess.new(semester_process_params.slice(:semester))
@semester_process.creator = current_user
@semester_process.build_semester_volunteers(@volunteers, selected_volunteers)
@semester_process.build_volunteers_hours_feedbacks_and_mails
authorize @semester_process
if @semester_process.save
redirect_to @semester_process, notice: 'Semester process was successfully created.'
......@@ -57,6 +60,12 @@ class SemesterProcessesController < ApplicationController
@volunteers = Volunteer.semester_process_eligible(@selected_semester)
end
def selected_volunteers
semester_process_params[:semester_process_volunteers_attributes]
.select { |_key, value| value['selected'] == '1' }
.to_h.map { |_key, value| value[:volunteer_id].to_i }
end
def semester_process_params
params.require(:semester_process).permit(
:semester,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment