2015-09-12 15:37:05 -05:00
|
|
|
class ParentsController < ApplicationController
|
|
|
|
def index
|
|
|
|
@parents = Person.just_parents
|
|
|
|
respond_with @parents
|
|
|
|
end
|
2015-09-24 22:00:26 -05:00
|
|
|
|
|
|
|
def show
|
2015-10-03 08:04:16 -05:00
|
|
|
@parent = Person.includes(:children).find_by_id(params[:id])
|
|
|
|
@more_children = Child.not_related_to(@parent.id)
|
2015-09-24 22:00:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2015-10-03 08:04:16 -05:00
|
|
|
@parent = Person.new
|
|
|
|
3.times { @parent.children.build }
|
2015-09-24 22:00:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def add
|
2015-10-03 08:04:16 -05:00
|
|
|
@parent = Person.create add_parent_params
|
|
|
|
|
|
|
|
if @parent.persisted?
|
|
|
|
redirect_to parent_path(@parent), notice: 'Success!'
|
|
|
|
return
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@parent = Person.includes(:children).find_by_id(params[:id])
|
|
|
|
@more_children = Child.all
|
2015-09-24 22:00:26 -05:00
|
|
|
end
|
2015-10-03 08:04:16 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def add_parent_params
|
|
|
|
params.require(:parent).permit(
|
|
|
|
:first_name,
|
|
|
|
:last_name,
|
|
|
|
:phone,
|
|
|
|
:email,
|
|
|
|
children_attributes: [:first_name, :last_name]
|
|
|
|
)
|
|
|
|
end
|
2015-09-12 15:37:05 -05:00
|
|
|
end
|