sms-pager/app/controllers/children_controller.rb

47 lines
877 B
Ruby

class ChildrenController < ApplicationController
def index
@children = Child.all.order(:last_name, :first_name)
respond_with @children
end
def show
@child = Child.includes(:parents).find_by_id(params[:id])
@parents = Person.order(:first_name, :last_name)
end
def new
@child = Child.new
end
def edit
@child = Child.find_by_id(params[:id])
end
def add
@child = Child.create child_params
if @child.persisted?
redirect_to child_path(@child), notice: 'Created!'
else
render :new
end
end
def update
@child = Child.find_by_id params[:id]
if @child.update child_params
redirect_to child_path(@child), notice: 'Updated!'
else
render :edit
end
end
private
def child_params
params.require(:child).permit(
:first_name,
:last_name
)
end
end