1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/controllers/api/age_ranges_controller.rb

53 lines
1.1 KiB
Ruby
Raw Normal View History

2019-01-08 09:56:07 +01:00
# frozen_string_literal: true
# API Controller for resources of type AgeRange
# AgeRange are used in Events
2023-02-24 17:26:55 +01:00
class API::AgeRangesController < API::APIController
before_action :authenticate_user!, except: [:index]
2019-01-08 09:56:07 +01:00
before_action :set_age_range, only: %i[show update destroy]
2016-06-29 11:21:21 +02:00
def index
@age_ranges = AgeRange.all
end
2019-01-08 09:56:07 +01:00
def show; end
2016-06-29 11:21:21 +02:00
def create
authorize AgeRange
@age_range = AgeRange.new(age_range_params)
if @age_range.save
render :show, status: :created, location: @age_range
else
render json: @age_range.errors, status: :unprocessable_entity
end
end
def update
authorize AgeRange
if @age_range.update(age_range_params)
render :show, status: :ok, location: @age_range
else
render json: @age_range.errors, status: :unprocessable_entity
end
end
def destroy
authorize AgeRange
if @age_range.safe_destroy
head :no_content
else
render json: @age_range.errors, status: :unprocessable_entity
end
2016-06-29 11:21:21 +02:00
end
private
2019-01-16 13:07:19 +01:00
2016-06-29 11:21:21 +02:00
def set_age_range
@age_range = AgeRange.find(params[:id])
end
def age_range_params
params.require(:age_range).permit(:name)
end
end