more scaffolding

This commit is contained in:
Jared Cosulich 2017-03-01 13:23:54 -05:00
parent 7e051222aa
commit 392696301c
66 changed files with 1110 additions and 241 deletions

View file

@ -0,0 +1,74 @@
class DistrictsController < ApplicationController
before_action :set_district, only: [:show, :edit, :update, :destroy]
# GET /districts
# GET /districts.json
def index
@districts = District.all
end
# GET /districts/1
# GET /districts/1.json
def show
end
# GET /districts/new
def new
@district = District.new
end
# GET /districts/1/edit
def edit
end
# POST /districts
# POST /districts.json
def create
@district = District.new(district_params)
respond_to do |format|
if @district.save
format.html { redirect_to @district, notice: 'District was successfully created.' }
format.json { render :show, status: :created, location: @district }
else
format.html { render :new }
format.json { render json: @district.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /districts/1
# PATCH/PUT /districts/1.json
def update
respond_to do |format|
if @district.update(district_params)
format.html { redirect_to @district, notice: 'District was successfully updated.' }
format.json { render :show, status: :ok, location: @district }
else
format.html { render :edit }
format.json { render json: @district.errors, status: :unprocessable_entity }
end
end
end
# DELETE /districts/1
# DELETE /districts/1.json
def destroy
@district.destroy
respond_to do |format|
format.html { redirect_to districts_url, notice: 'District was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_district
@district = District.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def district_params
params.require(:district).permit(:name, :state_id)
end
end

View file

@ -1,10 +1,11 @@
class RecipientsController < ApplicationController
before_action :set_school
before_action :set_recipient, only: [:show, :edit, :update, :destroy]
# GET /recipients
# GET /recipients.json
def index
@recipients = Recipient.all
@recipients = @school.recipients.all
end
# GET /recipients/1
@ -14,7 +15,7 @@ class RecipientsController < ApplicationController
# GET /recipients/new
def new
@recipient = Recipient.new
@recipient = @school.recipients.new
end
# GET /recipients/1/edit
@ -24,11 +25,11 @@ class RecipientsController < ApplicationController
# POST /recipients
# POST /recipients.json
def create
@recipient = Recipient.new(recipient_params)
@recipient = @school.recipients.new(recipient_params)
respond_to do |format|
if @recipient.save
format.html { redirect_to @recipient, notice: 'Recipient was successfully created.' }
format.html { redirect_to school_recipient_path(@school, @recipient), notice: 'Recipient was successfully created.' }
format.json { render :show, status: :created, location: @recipient }
else
format.html { render :new }
@ -42,7 +43,7 @@ class RecipientsController < ApplicationController
def update
respond_to do |format|
if @recipient.update(recipient_params)
format.html { redirect_to @recipient, notice: 'Recipient was successfully updated.' }
format.html { redirect_to school_recipient_path(@school, @recipient), notice: 'Recipient was successfully updated.' }
format.json { render :show, status: :ok, location: @recipient }
else
format.html { render :edit }
@ -56,15 +57,20 @@ class RecipientsController < ApplicationController
def destroy
@recipient.destroy
respond_to do |format|
format.html { redirect_to recipients_url, notice: 'Recipient was successfully destroyed.' }
format.html { redirect_to @school, notice: 'Recipient was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.find(params[:school_id])
end
# Use callbacks to share common setup or constraints between actions.
def set_recipient
@recipient = Recipient.find(params[:id])
@recipient = @school.recipients.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.

View file

@ -0,0 +1,74 @@
class SchoolsController < ApplicationController
before_action :set_school, only: [:show, :edit, :update, :destroy]
# GET /schools
# GET /schools.json
def index
@schools = School.all
end
# GET /schools/1
# GET /schools/1.json
def show
end
# GET /schools/new
def new
@school = School.new
end
# GET /schools/1/edit
def edit
end
# POST /schools
# POST /schools.json
def create
@school = School.new(school_params)
respond_to do |format|
if @school.save
format.html { redirect_to @school, notice: 'School was successfully created.' }
format.json { render :show, status: :created, location: @school }
else
format.html { render :new }
format.json { render json: @school.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /schools/1
# PATCH/PUT /schools/1.json
def update
respond_to do |format|
if @school.update(school_params)
format.html { redirect_to @school, notice: 'School was successfully updated.' }
format.json { render :show, status: :ok, location: @school }
else
format.html { render :edit }
format.json { render json: @school.errors, status: :unprocessable_entity }
end
end
end
# DELETE /schools/1
# DELETE /schools/1.json
def destroy
@school.destroy
respond_to do |format|
format.html { redirect_to schools_url, notice: 'School was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_school
@school = School.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def school_params
params.require(:school).permit(:name, :district_id)
end
end