Linked workers for the Particpant show page now work and link correctly!

This commit is contained in:
Ben 2024-01-22 23:46:09 -06:00
parent 9c6f980ccb
commit d817ae6992
3 changed files with 14 additions and 14 deletions

View File

@ -10,6 +10,7 @@ class ParticipantsController < ApplicationController
def show
@participant = Participant.includes(:employments).find(params[:id])
@workers = @participant.workers # Fetch associated workers
@employment = Employment.new # Initialize a new Employment object
end

View File

@ -1,4 +1,5 @@
class Employment < ApplicationRecord
belongs_to :worker
validates :worker, presence: true
belongs_to :participant
end

View File

@ -61,10 +61,9 @@
</div>
<h2>Linked Workers</h2>
<table class="table">
<thead>
<h2 class="mt-4">Linked Workers</h2>
<table class="table table-striped">
<thead class="table-dark">
<tr>
<th>Worker Name</th>
<th>Start Date</th>
@ -72,19 +71,17 @@
</tr>
</thead>
<tbody>
<% @participant.employments.each do |employment| %>
<tr>
<td><%= employment.worker.name %></td>
<td><%= employment.start_date %></td>
<td><%= employment.end_date %></td>
</tr>
<% end %>
<% @participant.employments.each do |employment| %>
<tr>
<td><%= employment.worker&.name || 'No Worker Assigned' %></td>
<td><%= employment.start_date %></td>
<td><%= employment.end_date %></td>
</tr>
<% end %>
</tbody>
</table>
<%= form_with(url: link_worker_participant_path(@participant), method: :post) do |form| %>
<%= form_with(model: [@participant, @employment], url: link_worker_participant_path(@participant), method: :post) do |form| %>
<div class="field">
<%= form.label :worker_id, "Select Worker" %>
<%= form.collection_select :worker_id, Worker.all, :id, :name, include_blank: true %>
@ -102,3 +99,4 @@
<%= form.submit "Link Worker" %>
<% end %>