From 16914c874b3dfe44fbaf49f6673c8eeed4ab7913 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Thu, 11 Jul 2024 23:30:02 +0200 Subject: [PATCH] Define unbreakable bonds in seed file and guest index --- app/controllers/guests_controller.rb | 2 +- app/views/guests/index.html.erb | 2 ++ db/seeds.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index b47ec8e..85e821d 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.includes(:affinity_groups) + @guests = Guest.all.includes(:affinity_groups, :unbreakable_bonds) 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 a5f8b60..436a01b 100644 --- a/app/views/guests/index.html.erb +++ b/app/views/guests/index.html.erb @@ -10,6 +10,7 @@ Email Phone Affinity groups + Unbreakable bonds <% @guests.each_with_index do |guest, i| %> @@ -19,6 +20,7 @@ <%= guest.email %> <%= guest.phone %> <%= guest.affinity_groups.pluck(:name).join(", ") %> + <%= guest.unbreakable_bonds.pluck(:name).join(", ") %> <%= link_to "Show", guest %> <%= link_to "Edit", edit_guest_path(guest) %> diff --git a/db/seeds.rb b/db/seeds.rb index 94122ff..2c8427b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -59,3 +59,14 @@ end guest.affinity_group_list.add(samples.sample) guest.save! end + + +Guest.all.sample(100).each_slice(2) do |a, b| + bond_name = "#{a.full_name} & #{b.full_name}" + + a.unbreakable_bond_list.add(bond_name) + b.unbreakable_bond_list.add(bond_name) + + a.save! + b.save! +end \ No newline at end of file