From 0814c7cab5bf8050a9757c3d74dae8508016dc59 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Thu, 11 Jul 2024 23:20:32 +0200 Subject: [PATCH] Avoid N+1 queries with acts_as_taggable --- app/controllers/guests_controller.rb | 2 +- app/views/guests/index.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index bc2a451..b47ec8e 100644 --- a/app/controllers/guests_controller.rb +++ b/app/controllers/guests_controller.rb @@ -3,7 +3,7 @@ class GuestsController < ApplicationController # GET /guests or /guests.json def index - @guests = Guest.all + @guests = Guest.all.includes(:affinity_groups) end # GET /guests/1 or /guests/1.json diff --git a/app/views/guests/index.html.erb b/app/views/guests/index.html.erb index 690588c..a5f8b60 100644 --- a/app/views/guests/index.html.erb +++ b/app/views/guests/index.html.erb @@ -18,7 +18,7 @@ <%= guest.full_name %> <%= guest.email %> <%= guest.phone %> - <%= guest.affinity_group_list %> + <%= guest.affinity_groups.pluck(:name).join(", ") %> <%= link_to "Show", guest %> <%= link_to "Edit", edit_guest_path(guest) %>