wedding-planner/app/controllers/guests_controller.rb

34 lines
754 B
Ruby
Raw Permalink Normal View History

2024-10-27 21:42:45 +00:00
# Copyright (C) 2024 Manuel Bustillo
2024-07-25 10:47:49 +02:00
require 'csv'
2024-07-11 20:08:26 +02:00
class GuestsController < ApplicationController
def index
render json: Guest.all.includes(:group)
.left_joins(:group)
.order('groups.name' => :asc, name: :asc)
.as_json(only: %i[id name status], include: { group: { only: %i[id name] } })
2024-07-11 20:08:26 +02:00
end
def create
2024-11-17 20:01:23 +01:00
Guest.create!(guest_params)
render json: {}, status: :created
end
def update
2024-11-17 20:01:23 +01:00
Guest.find(params[:id]).update!(guest_params)
render json: {}, status: :ok
end
2024-11-17 18:24:43 +01:00
def destroy
Guest.find(params[:id]).destroy!
render json: {}, status: :ok
end
2024-11-17 20:01:23 +01:00
private
def guest_params
params.require(:guest).permit(:name, :group_id, :status)
end
2024-07-11 20:08:26 +02:00
end