From de03804a8f4ba1e44db53db89591a47e48c46198 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 5 Feb 2024 16:18:06 -0600 Subject: [PATCH] Properly Linked Employers to Worker Details view going through the Participant Employer Record. --- app/models/employer.rb | 3 +++ app/models/worker.rb | 3 ++- app/views/workers/show.html.erb | 40 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/models/employer.rb b/app/models/employer.rb index 9da1636..1968db9 100644 --- a/app/models/employer.rb +++ b/app/models/employer.rb @@ -10,4 +10,7 @@ class Employer < ApplicationRecord has_many :workers, through: :direct_participants # Other methods... + def full_name + "#{first_name} #{last_name}" + end end diff --git a/app/models/worker.rb b/app/models/worker.rb index 66ce65a..f124b89 100644 --- a/app/models/worker.rb +++ b/app/models/worker.rb @@ -6,7 +6,8 @@ class Worker < ApplicationRecord has_many :participants, through: :employments # Many-to-many relationship with Employers through Participants - has_many :employers, through: :participants + has_many :employers, through: :participants, source: :employer + has_many :employer_records, through: :participants # Validations validates :first_name, presence: true diff --git a/app/views/workers/show.html.erb b/app/views/workers/show.html.erb index f6bac94..4af92aa 100644 --- a/app/views/workers/show.html.erb +++ b/app/views/workers/show.html.erb @@ -114,6 +114,43 @@ <% end %> +
+
+

Linked Employers

+ <% if @worker.participants.any? %> + + + + + + + + + + + <% @worker.participants.each do |participant| %> + <% participant.employer_records.each do |employer_record| %> + + + + + + + <% end %> + <% end %> + +
Employer NameStart DateEnd DateActions
<%= employer_record.employer.full_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 'View', employer_path(employer_record.employer), class: 'btn btn-sm btn-secondary' %> + <%= link_to 'Edit', edit_employer_record_path(employer_record), class: 'btn btn-sm btn-info' %> +
+ <% else %> +

No linked employers.

+ <% end %> +
+
+ + + <%# JavaScript for Participant Autocomplete %> @@ -145,3 +182,6 @@ $(document).ready(function() { + + +