60 lines
1.2 KiB
Ruby
60 lines
1.2 KiB
Ruby
|
class TeachersController < ApplicationController
|
||
|
before_action :set_teacher, only: %i[ show edit update destroy ]
|
||
|
|
||
|
# GET /teachers
|
||
|
def index
|
||
|
@teachers = Teacher.all
|
||
|
end
|
||
|
|
||
|
# GET /teachers/1
|
||
|
def show
|
||
|
end
|
||
|
|
||
|
# GET /teachers/new
|
||
|
def new
|
||
|
@teacher = Teacher.new
|
||
|
end
|
||
|
|
||
|
# GET /teachers/1/edit
|
||
|
def edit
|
||
|
end
|
||
|
|
||
|
# POST /teachers
|
||
|
def create
|
||
|
@teacher = Teacher.new(teacher_params)
|
||
|
@teacher.member = current_member
|
||
|
|
||
|
if @teacher.save
|
||
|
redirect_to @teacher, notice: "Successfully created Teacher profile"
|
||
|
else
|
||
|
render :new, status: :unprocessable_entity
|
||
|
end
|
||
|
end
|
||
|
|
||
|
# PATCH/PUT /teachers/1
|
||
|
def update
|
||
|
if @teacher.update(teacher_params)
|
||
|
redirect_to @teacher, notice: "Teacher Profile was updated."
|
||
|
else
|
||
|
render :edit, status: :unprocessable_entity
|
||
|
end
|
||
|
end
|
||
|
|
||
|
# DELETE /teachers/1
|
||
|
def destroy
|
||
|
@teacher.destroy
|
||
|
redirect_to teachers_url, notice: "Teacher was successfully destroyed."
|
||
|
end
|
||
|
|
||
|
private
|
||
|
# Use callbacks to share common setup or constraints between actions.
|
||
|
def set_teacher
|
||
|
@teacher = Teacher.find(params[:id])
|
||
|
end
|
||
|
|
||
|
# Only allow a list of trusted parameters through.
|
||
|
def teacher_params
|
||
|
params.require(:teacher).permit(:name, :bio, :picture)
|
||
|
end
|
||
|
end
|