parent/child CRUD complete

This commit is contained in:
2015-10-03 19:16:46 -05:00
parent 0510f1c4c2
commit 7afe8d137c
17 changed files with 144 additions and 26 deletions

View File

@ -4,5 +4,43 @@ class ChildrenController < ApplicationController
respond_with @children
end
def lookup; 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

View File

@ -1,8 +1,8 @@
class DocsController < ApplicationController
def index
@doc = {
name: "sms-pager-api",
documentation: "https://bitbucket.org/markamoser/sms-pager-api"
name: "sms-pager",
documentation: "https://bitbucket.org/markamoser/sms-pager"
}
respond_with @doc
end

View File

@ -15,7 +15,7 @@ class ParentsController < ApplicationController
end
def add
@parent = Person.create add_parent_params
@parent = Person.create parent_params
if @parent.persisted?
redirect_to parent_path(@parent), notice: 'Success!'
@ -30,9 +30,19 @@ class ParentsController < ApplicationController
@more_children = Child.all
end
def update
@parent = Person.find(params[:id])
if @parent.update(parent_params)
redirect_to parent_path(@parent), notice: 'Success!'
else
render :edit
end
end
private
def add_parent_params
def parent_params
params.require(:parent).permit(
:first_name,
:last_name,