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
2023-03-22 10:58:22 +01:00

53 lines
1.1 KiB
Ruby

# frozen_string_literal: true
# API Controller for resources of type AgeRange
# AgeRange are used in Events
class API::AgeRangesController < API::APIController
before_action :authenticate_user!, except: [:index]
before_action :set_age_range, only: %i[show update destroy]
def index
@age_ranges = AgeRange.all
end
def show; end
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
end
private
def set_age_range
@age_range = AgeRange.find(params[:id])
end
def age_range_params
params.require(:age_range).permit(:name)
end
end