BenMusch/nu-tab

View on GitHub
app/controllers/schools_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true
Add an empty line after magic comments.
class SchoolsController < ApplicationController
Use `%i` or `%I` for an array of symbols.
before_action :set_school, only: [:show, :edit, :update, :destroy]
 
# GET /schools
def index
@schools = School.all
end
 
# GET /schools/1
Put empty method definitions on a single line.
def show
end
 
# GET /schools/new
def new
@school = School.new
end
 
# GET /schools/1/edit
Put empty method definitions on a single line.
def edit
end
 
# POST /schools
def create
@school = School.new(school_params)
 
if @school.save
redirect_to @school, notice: 'School was successfully created.'
else
render :new
end
end
 
# PATCH/PUT /schools/1
def update
if @school.update(school_params)
redirect_to @school, notice: 'School was successfully updated.'
else
render :edit
end
end
 
# DELETE /schools/1
def destroy
@school.destroy
redirect_to schools_url, notice: 'School was successfully destroyed.'
end
 
private
 
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.find(params[:id])
end
 
# Only allow a trusted parameter "white list" through.
def school_params
params.require(:school).permit(:name)
end
end