Compare commits

..

5 Commits

3 changed files with 42 additions and 20 deletions

View File

@ -3,12 +3,14 @@ class GuestsController < ApplicationController
# GET /guests or /guests.json
def index
@guests = Guest.all.includes(:affinity_groups)
@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,12 +53,13 @@ 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])

View File

@ -10,6 +10,7 @@
<th>Email</th>
<th>Phone</th>
<th>Affinity groups</th>
<th>Unbreakable bonds</th>
<th colspan="2"></th>
</tr>
<% @guests.each_with_index do |guest, i| %>
@ -19,6 +20,7 @@
<td><%= guest.email %></td>
<td><%= guest.phone %></td>
<td><%= guest.affinity_groups.pluck(:name).join(", ") %></td>
<td><%= guest.unbreakable_bonds.pluck(:name).join(", ") %></td>
<td><%= link_to "Show", guest %></td>
<td><%= link_to "Edit", edit_guest_path(guest) %></td>
</tr>

View File

@ -28,7 +28,10 @@ Expense.create!(name: 'Transportation', amount: 3000, pricing_type: 'fixed')
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
<<<<<<< HEAD
=======
>>>>>>> 8fd0b7c (Modify seeds file to make sure every guest is part of a group)
samples = {
close_family: 10,
family_1_group_a: 5,
@ -56,3 +59,18 @@ end
guest.affinity_group_list.add(samples.sample)
guest.save!
end
Guest.affinity_group_counts.each do |group|
couples = (group.taggings_count / 4).floor
guests_involved = Guest.tagged_with(group.name).limit(couples * 2)
guests_involved.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
end