sms-pager/app/controllers/parents_controller.rb

45 lines
880 B
Ruby
Raw Normal View History

2015-09-12 15:37:05 -05:00
class ParentsController < ApplicationController
def index
@parents = Person.just_parents
respond_with @parents
end
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)
end
def new
2015-10-03 08:04:16 -05:00
@parent = Person.new
3.times { @parent.children.build }
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
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