Class: Kidspire::Api::V1::ChildrenController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/kidspire/api/v1/children_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
# File 'app/controllers/kidspire/api/v1/children_controller.rb', line 12

def create
  child = current_family.children.build(child_params)
  if child.save
    render json: ChildBlueprint.render(child), status: :created
  else
    render json: { error: child.errors.full_messages.first, code: "validation_error" },
           status: :unprocessable_entity
  end
end

#destroyObject



31
32
33
34
# File 'app/controllers/kidspire/api/v1/children_controller.rb', line 31

def destroy
  @child.destroy
  head :no_content
end

#indexObject



8
9
10
# File 'app/controllers/kidspire/api/v1/children_controller.rb', line 8

def index
  render json: ChildBlueprint.render(current_family.children.order(:first_name, :last_name))
end

#updateObject



22
23
24
25
26
27
28
29
# File 'app/controllers/kidspire/api/v1/children_controller.rb', line 22

def update
  if @child.update(child_params)
    render json: ChildBlueprint.render(@child)
  else
    render json: { error: @child.errors.full_messages.first, code: "validation_error" },
           status: :unprocessable_entity
  end
end