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
|
def show
|
||||||
@participant = Participant.includes(:employments).find(params[:id])
|
@participant = Participant.includes(:employments).find(params[:id])
|
||||||
@workers = @participant.workers # Fetch associated workers
|
@workers = @participant.workers # Fetch associated workers
|
||||||
|
@employment = Employment.new # Initialize a new Employment object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class Employment < ApplicationRecord
|
class Employment < ApplicationRecord
|
||||||
belongs_to :worker
|
belongs_to :worker
|
||||||
|
validates :worker, presence: true
|
||||||
belongs_to :participant
|
belongs_to :participant
|
||||||
end
|
end
|
||||||
|
|
|
@ -61,10 +61,9 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<h2>Linked Workers</h2>
|
<h2 class="mt-4">Linked Workers</h2>
|
||||||
|
<table class="table table-striped">
|
||||||
<table class="table">
|
<thead class="table-dark">
|
||||||
<thead>
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>Worker Name</th>
|
<th>Worker Name</th>
|
||||||
<th>Start Date</th>
|
<th>Start Date</th>
|
||||||
|
@ -74,7 +73,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @participant.employments.each do |employment| %>
|
<% @participant.employments.each do |employment| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= employment.worker.name %></td>
|
<td><%= employment.worker&.name || 'No Worker Assigned' %></td>
|
||||||
<td><%= employment.start_date %></td>
|
<td><%= employment.start_date %></td>
|
||||||
<td><%= employment.end_date %></td>
|
<td><%= employment.end_date %></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -82,9 +81,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<%= form_with(model: [@participant, @employment], url: link_worker_participant_path(@participant), method: :post) do |form| %>
|
||||||
|
|
||||||
<%= form_with(url: link_worker_participant_path(@participant), method: :post) do |form| %>
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= form.label :worker_id, "Select Worker" %>
|
<%= form.label :worker_id, "Select Worker" %>
|
||||||
<%= form.collection_select :worker_id, Worker.all, :id, :name, include_blank: true %>
|
<%= form.collection_select :worker_id, Worker.all, :id, :name, include_blank: true %>
|
||||||
|
@ -102,3 +99,4 @@
|
||||||
|
|
||||||
<%= form.submit "Link Worker" %>
|
<%= form.submit "Link Worker" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue