From 3f9358997b597a51a382bfb1574323411f665f59 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 5 Feb 2024 15:58:46 -0600 Subject: [PATCH] Linked Workers to the Employer Details show view --- app/controllers/employers_controller.rb | 2 +- app/models/employer.rb | 21 +++--- app/views/employers/show.html.erb | 87 ++++++++++++++++++------- 3 files changed, 74 insertions(+), 36 deletions(-) diff --git a/app/controllers/employers_controller.rb b/app/controllers/employers_controller.rb index 705fb36..5084659 100644 --- a/app/controllers/employers_controller.rb +++ b/app/controllers/employers_controller.rb @@ -8,7 +8,7 @@ class EmployersController < ApplicationController # GET /employers/:id def show - @employer = Employer.includes(:employer_records, :participants).find(params[:id]) + @employer = Employer.includes(:employer_records, :direct_participants).find(params[:id]) @employer_records = @employer.employer_records.includes(:participant) end diff --git a/app/models/employer.rb b/app/models/employer.rb index d2cb5ca..9da1636 100644 --- a/app/models/employer.rb +++ b/app/models/employer.rb @@ -1,14 +1,13 @@ class Employer < ApplicationRecord - has_many :participants - has_many :workers, through: :participants - has_many :employer_records - has_many :participants, through: :employer_records + # Direct association with participants + has_many :direct_participants, class_name: 'Participant' - # Association with Vendor if needed + # Association through EmployerRecord + has_many :employer_records + has_many :indirect_participants, through: :employer_records, source: :participant - def full_name - "#{first_name} #{last_name}" - end - - end - \ No newline at end of file + # Association with Workers through direct_participants + has_many :workers, through: :direct_participants + + # Other methods... +end diff --git a/app/views/employers/show.html.erb b/app/views/employers/show.html.erb index d22ccb2..a206e56 100644 --- a/app/views/employers/show.html.erb +++ b/app/views/employers/show.html.erb @@ -54,15 +54,14 @@ -
- - -
-
-

Linked Participants

- <% if @employer.employer_records.any? %> - +
+
+ +
+

Linked Participants

+ <% if @employer.employer_records.any? %> +
@@ -72,29 +71,69 @@ - <% @employer.employer_records.each do |employer_record| %> - - <% participant = employer_record.participant %> - - - - - - <% end %> + <% @employer.employer_records.each do |employer_record| %> + + <% participant = employer_record.participant %> + + + + + + <% end %>
Participant Name
<%= "#{participant.first_name} #{participant.last_name}" %><%= employer_record.start_date.strftime('%B %d, %Y') if employer_record.start_date %><%= employer_record.end_date.strftime('%B %d, %Y') if employer_record.end_date %> - <%= link_to participant_path(participant), class: 'btn btn-sm btn-secondary' do %> - - <% end %> - <%= link_to edit_employer_record_path(employer_record), class: 'btn btn-sm btn-info' do %> - - <% end %> -
<%= "#{participant.first_name} #{participant.last_name}" %><%= employer_record.start_date.strftime('%B %d, %Y') if employer_record.start_date %><%= employer_record.end_date.strftime('%B %d, %Y') if employer_record.end_date %> + <%= link_to participant_path(participant), class: 'btn btn-sm btn-secondary' do %> + + <% end %> + <%= link_to edit_employer_record_path(employer_record), class: 'btn btn-sm btn-info' do %> + + <% end %> +
<% else %>

No linked participants.

<% end %>
+ +
+

Linked Workers

+ <% if @employer.workers.any? %> + + + + + + + + + + + <% @employer.workers.each do |worker| %> + <% worker.employments.joins(:participant).where(participants: { employer_id: @employer.id }).each do |employment| %> + + + + + + + <% end %> + <% end %> + +
Worker NameStart DateEnd DateActions
<%= worker.full_name %><%= employment.start_date.strftime('%B %d, %Y') if employment.start_date %><%= employment.end_date.strftime('%B %d, %Y') if employment.end_date %> + <%= link_to worker_path(worker), class: 'btn btn-sm btn-secondary' do %> + + <% end %> + <%= link_to edit_employment_path(employment), class: 'btn btn-sm btn-info' do %> + + <% end %> +
+ <% else %> +

No linked workers.

+ <% end %> + +
+
+ \ No newline at end of file