You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sqm-dashboards/app/controllers/recipients_controller.rb

81 lines
2.3 KiB

class RecipientsController < ApplicationController
before_action :set_school
before_action :set_recipient, only: [:show, :edit, :update, :destroy]
# GET /recipients
# GET /recipients.json
def index
@recipients = @school.recipients.all
end
# GET /recipients/1
# GET /recipients/1.json
def show
end
# GET /recipients/new
def new
@recipient = @school.recipients.new
end
# GET /recipients/1/edit
def edit
end
# POST /recipients
# POST /recipients.json
def create
@recipient = @school.recipients.new(recipient_params)
respond_to do |format|
if @recipient.save
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 }
format.json { render json: @recipient.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /recipients/1
# PATCH/PUT /recipients/1.json
def update
respond_to do |format|
if @recipient.update(recipient_params)
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 }
format.json { render json: @recipient.errors, status: :unprocessable_entity }
end
end
end
# DELETE /recipients/1
# DELETE /recipients/1.json
def destroy
@recipient.destroy
respond_to do |format|
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 = @school.recipients.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def recipient_params
params.require(:recipient).permit(:name, :phone, :birth_date, :gender, :race, :ethnicity, :home_language_id, :income, :opted_out, :school_id)
end
end