hubfeenix.fi/app/controllers/teachers_controller.rb

63 lines
1.3 KiB
Ruby

class TeachersController < ApplicationController
before_action :set_teacher, only: %i[ show edit update destroy ]
# GET /teachers
def index
@teachers = Teacher.page params[:page]
end
# GET /teachers/1
def show
end
# GET /teachers/new
def new
@teacher = Teacher.new
end
# GET /teachers/1/edit
def edit
authorize @teacher
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
authorize @teacher
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
authorize @teacher
@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