Linked Workers are now editable and removeable from a Participant. Also created the associated Controller and Edit view for said actions.
This commit is contained in:
parent
38e4553e33
commit
95dd6dca7e
|
@ -0,0 +1,32 @@
|
|||
class EmploymentsController < ApplicationController
|
||||
before_action :set_employment, only: [:edit, :update, :destroy]
|
||||
|
||||
def edit
|
||||
# Edit view will be rendered
|
||||
end
|
||||
|
||||
def update
|
||||
if @employment.update(employment_params)
|
||||
redirect_to participant_path(@employment.participant), notice: 'Employment was successfully updated.'
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
participant = @employment.participant
|
||||
@employment.destroy
|
||||
redirect_to participant_path(participant), notice: 'Employment was successfully removed.'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_employment
|
||||
@employment = Employment.find(params[:id])
|
||||
end
|
||||
|
||||
def employment_params
|
||||
params.require(:employment).permit(:start_date, :end_date)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module EmploymentsHelper
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
<h1>Edit Employment</h1>
|
||||
|
||||
<%= form_with(model: @employment, url: employment_path(@employment), method: :patch) do |form| %>
|
||||
<div class="field">
|
||||
<%= form.label :start_date %>
|
||||
<%= form.date_field :start_date %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :end_date %>
|
||||
<%= form.date_field :end_date %>
|
||||
</div>
|
||||
|
||||
<%= form.submit "Update Employment" %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back to Participant', participant_path(@employment.participant) %>
|
|
@ -68,19 +68,25 @@
|
|||
<th>Worker Name</th>
|
||||
<th>Start Date</th>
|
||||
<th>End Date</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @participant.employments.each do |employment| %>
|
||||
<tr>
|
||||
<td><%= employment.worker&.name || 'No Worker Assigned' %></td>
|
||||
<td><%= employment.start_date.strftime('%B %d, %Y') if employment.start_date.present? %></td>
|
||||
<td><%= employment.end_date.strftime('%B %d, %Y') if employment.end_date.present? %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% @participant.employments.each do |employment| %>
|
||||
<tr>
|
||||
<td><%= employment.worker&.name || 'No Worker Assigned' %></td>
|
||||
<td><%= employment.start_date.strftime('%B %d, %Y') if employment.start_date.present? %></td>
|
||||
<td><%= employment.end_date.strftime('%B %d, %Y') if employment.end_date.present? %></td>
|
||||
<td>
|
||||
<%= link_to 'Edit', edit_employment_path(employment), class: 'btn btn-sm btn-primary' %>
|
||||
<%= link_to 'Remove', employment, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-sm btn-danger' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<%= form_with(model: [@participant, @employment], url: link_worker_participant_path(@participant), method: :post, class: 'row g-3') do |form| %>
|
||||
<div class="col-md-6">
|
||||
<%= form.label :worker_id, "Select Worker", class: 'form-label' %>
|
||||
|
|
|
@ -16,6 +16,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
resources :workers
|
||||
resources :vendors
|
||||
resources :employments, only: [:edit, :update, :destroy]
|
||||
resources :employers do
|
||||
get 'search', on: :collection
|
||||
end
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class EmploymentsControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in New Issue