71 lines
1.9 KiB
Ruby
71 lines
1.9 KiB
Ruby
class TeachersController < ApplicationController
|
|
before_action :set_teacher, only: %i[ show edit update destroy ]
|
|
|
|
# GET /teachers or /teachers.json
|
|
def index
|
|
@teachers = Teacher.all
|
|
end
|
|
|
|
# GET /teachers/1 or /teachers/1.json
|
|
def show
|
|
end
|
|
|
|
# GET /teachers/new
|
|
def new
|
|
@teacher = Teacher.new
|
|
end
|
|
|
|
# GET /teachers/1/edit
|
|
def edit
|
|
end
|
|
|
|
# POST /teachers or /teachers.json
|
|
def create
|
|
@teacher = Teacher.new(teacher_params)
|
|
|
|
respond_to do |format|
|
|
if @teacher.save
|
|
format.html { redirect_to @teacher, notice: "Teacher was successfully created." }
|
|
format.json { render :show, status: :created, location: @teacher }
|
|
else
|
|
format.html { render :new, status: :unprocessable_entity }
|
|
format.json { render json: @teacher.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# PATCH/PUT /teachers/1 or /teachers/1.json
|
|
def update
|
|
respond_to do |format|
|
|
if @teacher.update(teacher_params)
|
|
format.html { redirect_to @teacher, notice: "Teacher was successfully updated.", status: :see_other }
|
|
format.json { render :show, status: :ok, location: @teacher }
|
|
else
|
|
format.html { render :edit, status: :unprocessable_entity }
|
|
format.json { render json: @teacher.errors, status: :unprocessable_entity }
|
|
end
|
|
end
|
|
end
|
|
|
|
# DELETE /teachers/1 or /teachers/1.json
|
|
def destroy
|
|
@teacher.destroy!
|
|
|
|
respond_to do |format|
|
|
format.html { redirect_to teachers_path, notice: "Teacher was successfully destroyed.", status: :see_other }
|
|
format.json { head :no_content }
|
|
end
|
|
end
|
|
|
|
private
|
|
# Use callbacks to share common setup or constraints between actions.
|
|
def set_teacher
|
|
@teacher = Teacher.find(params.expect(:id))
|
|
end
|
|
|
|
# Only allow a list of trusted parameters through.
|
|
def teacher_params
|
|
params.expect(teacher: [ :name, :school, :subject, :place ])
|
|
end
|
|
end
|