2015-09-12 15:37:05 -05:00
|
|
|
class ChildrenController < ApplicationController
|
2015-09-18 15:50:52 -05:00
|
|
|
def index
|
|
|
|
@children = Child.all.order(:last_name, :first_name)
|
|
|
|
respond_with @children
|
|
|
|
end
|
2015-09-20 13:26:45 -05:00
|
|
|
|
2015-10-03 19:16:46 -05:00
|
|
|
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
|
2015-09-12 15:37:05 -05:00
|
|
|
end
|