sms-pager/app/controllers/parents_controller.rb

45 lines
880 B
Ruby

class ParentsController < ApplicationController
def index
@parents = Person.just_parents
respond_with @parents
end
def show
@parent = Person.includes(:children).find_by_id(params[:id])
@more_children = Child.not_related_to(@parent.id)
end
def new
@parent = Person.new
3.times { @parent.children.build }
end
def add
@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
end
private
def add_parent_params
params.require(:parent).permit(
:first_name,
:last_name,
:phone,
:email,
children_attributes: [:first_name, :last_name]
)
end
end