Properly Linked Employers to Worker Details view going through the Participant Employer Record.
This commit is contained in:
parent
3f9358997b
commit
de03804a8f
|
@ -10,4 +10,7 @@ class Employer < ApplicationRecord
|
|||
has_many :workers, through: :direct_participants
|
||||
|
||||
# Other methods...
|
||||
def full_name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -114,6 +114,43 @@
|
|||
<% end %>
|
||||
|
||||
|
||||
<div class="row mt-4">
|
||||
<div class="col-md-6">
|
||||
<h2 class="mt-4">Linked Employers</h2>
|
||||
<% if @worker.participants.any? %>
|
||||
<table class="table table-striped">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>Employer Name</th>
|
||||
<th>Start Date</th>
|
||||
<th>End Date</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @worker.participants.each do |participant| %>
|
||||
<% participant.employer_records.each do |employer_record| %>
|
||||
<tr>
|
||||
<td><%= employer_record.employer.full_name %></td>
|
||||
<td><%= employer_record.start_date.strftime('%B %d, %Y') if employer_record.start_date %></td>
|
||||
<td><%= employer_record.end_date.strftime('%B %d, %Y') if employer_record.end_date %></td>
|
||||
<td>
|
||||
<%= 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' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p>No linked employers.</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<%# JavaScript for Participant Autocomplete %>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://code.jquery.com/ui/1.13.0/jquery-ui.min.js"></script>
|
||||
|
@ -145,3 +182,6 @@ $(document).ready(function() {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue