Linked workers for the Particpant show page now work and link correctly!
This commit is contained in:
parent
9c6f980ccb
commit
d817ae6992
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Employment < ApplicationRecord
|
||||
belongs_to :worker
|
||||
validates :worker, presence: true
|
||||
belongs_to :participant
|
||||
end
|
||||
|
|
|
@ -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>
|
||||
|
@ -74,7 +73,7 @@
|
|||
<tbody>
|
||||
<% @participant.employments.each do |employment| %>
|
||||
<tr>
|
||||
<td><%= employment.worker.name %></td>
|
||||
<td><%= employment.worker&.name || 'No Worker Assigned' %></td>
|
||||
<td><%= employment.start_date %></td>
|
||||
<td><%= employment.end_date %></td>
|
||||
</tr>
|
||||
|
@ -82,9 +81,7 @@
|
|||
</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 %>
|
||||
|
||||
|
|
Loading…
Reference in New Issue