From 8732dac0a38b3c5391895064df1e7fc7eda0f698 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Fri, 12 Jul 2024 15:08:30 +0200 Subject: [PATCH] Order guests by affinity group --- app/controllers/guests_controller.rb | 36 +++++++++++++++------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index 85e821d..025f7ef 100644 --- a/app/controllers/guests_controller.rb +++ b/app/controllers/guests_controller.rb @@ -1,14 +1,16 @@ class GuestsController < ApplicationController - before_action :set_guest, only: %i[ show edit update destroy ] + before_action :set_guest, only: %i[show edit update destroy] # GET /guests or /guests.json def index - @guests = Guest.all.includes(:affinity_groups, :unbreakable_bonds) + @guests = Guest.all + .left_outer_joins(:affinity_groups) + .order('tags.name' => :asc) + .includes(:affinity_groups, :unbreakable_bonds) end # GET /guests/1 or /guests/1.json - def show - end + def show; end # GET /guests/new def new @@ -16,8 +18,7 @@ class GuestsController < ApplicationController end # GET /guests/1/edit - def edit - end + def edit; end # POST /guests or /guests.json def create @@ -25,7 +26,7 @@ class GuestsController < ApplicationController respond_to do |format| if @guest.save - format.html { redirect_to guest_url(@guest), notice: "Guest was successfully created." } + format.html { redirect_to guest_url(@guest), notice: 'Guest was successfully created.' } format.json { render :show, status: :created, location: @guest } else format.html { render :new, status: :unprocessable_entity } @@ -38,7 +39,7 @@ class GuestsController < ApplicationController def update respond_to do |format| if @guest.update(guest_params) - format.html { redirect_to guest_url(@guest), notice: "Guest was successfully updated." } + format.html { redirect_to guest_url(@guest), notice: 'Guest was successfully updated.' } format.json { render :show, status: :ok, location: @guest } else format.html { render :edit, status: :unprocessable_entity } @@ -52,19 +53,20 @@ class GuestsController < ApplicationController @guest.destroy! respond_to do |format| - format.html { redirect_to guests_url, notice: "Guest was successfully destroyed." } + format.html { redirect_to guests_url, notice: 'Guest was successfully destroyed.' } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_guest - @guest = Guest.find(params[:id]) - end - # Only allow a list of trusted parameters through. - def guest_params - params.require(:guest).permit(:first_name, :last_name, :email, :phone) - end + # Use callbacks to share common setup or constraints between actions. + def set_guest + @guest = Guest.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def guest_params + params.require(:guest).permit(:first_name, :last_name, :email, :phone) + end end