-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fd5a31
commit a1c5f3f
Showing
2 changed files
with
10 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 3 additions & 68 deletions
71
app/controllers/placements/support/schools/mentors_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,11 @@ | ||
class Placements::Support::Schools::MentorsController < Placements::ApplicationController | ||
before_action :set_school | ||
before_action :set_mentor, only: %i[show remove destroy] | ||
before_action :set_mentor_membership, only: %i[remove destroy] | ||
|
||
def index | ||
@pagy, @mentors = pagy(@school.mentors.order_by_full_name) | ||
end | ||
|
||
def show; end | ||
|
||
def new | ||
mentor_form | ||
end | ||
|
||
def check | ||
render :new unless mentor_form.valid? | ||
rescue TeachingRecord::RestClient::TeacherNotFoundError | ||
render :no_results | ||
end | ||
|
||
def create | ||
mentor_form.save! | ||
|
||
redirect_to placements_support_school_mentors_path(@school), flash: { success: t(".mentor_added") } | ||
end | ||
|
||
def remove | ||
if policy(@mentor_membership).destroy? | ||
render "confirm_remove" | ||
else | ||
render "can_not_remove" | ||
end | ||
end | ||
|
||
def destroy | ||
authorize @mentor_membership | ||
@mentor_membership.destroy! | ||
|
||
redirect_to placements_support_school_mentors_path(@school) | ||
flash[:success] = t(".mentor_removed") | ||
end | ||
|
||
class Placements::Support::Schools::MentorsController < Placements::Schools::MentorsController | ||
private | ||
|
||
def mentor_params | ||
params.require(:placements_mentor_form) | ||
.permit(:first_name, :last_name, :trn, :date_of_birth) | ||
.merge(default_params) | ||
end | ||
|
||
def default_params | ||
{ school: @school } | ||
end | ||
|
||
def mentor_form | ||
@mentor_form ||= | ||
if params[:placements_mentor_form].present? | ||
Placements::MentorForm.new(mentor_params) | ||
else | ||
Placements::MentorForm.new(default_params) | ||
end | ||
end | ||
|
||
def set_school | ||
@school = Placements::School.find(params.fetch(:school_id)) | ||
end | ||
|
||
def set_mentor | ||
@mentor = @school.mentors.find(params.fetch(:id)) | ||
end | ||
|
||
def set_mentor_membership | ||
@mentor_membership = @mentor.mentor_memberships.find_by(school: @school) | ||
def redirect_to_index_path | ||
redirect_to placements_support_school_mentors_path(@school) | ||
end | ||
end |