|
|
@ -14,14 +14,22 @@ class CreaturesController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
def create
|
|
|
|
@creature = Creature.new(create_params)
|
|
|
|
@creature = Creature.new(create_or_update_params)
|
|
|
|
@creature.health_points = rand(3..30)
|
|
|
|
@creature.health_points = rand(3..30)
|
|
|
|
@creature.save!
|
|
|
|
@creature.save!
|
|
|
|
render json: @creature.as_json(only: SHOWABLE_ATTRIBUTES)
|
|
|
|
render json: @creature.as_json(only: SHOWABLE_ATTRIBUTES)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
|
|
|
@creature = Creature.find(params[:id])
|
|
|
|
|
|
|
|
@creature.update!(create_or_update_params)
|
|
|
|
|
|
|
|
render json: @creature.as_json(only: SHOWABLE_ATTRIBUTES)
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
|
|
|
render json: {}, status: 404
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
private
|
|
|
|
def create_params
|
|
|
|
def create_or_update_params
|
|
|
|
params.require(:creature).permit(:name)
|
|
|
|
params.require(:creature).permit(:name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|