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>Worker Name</th>
|
||||||
<th>Start Date</th>
|
<th>Start Date</th>
|
||||||
<th>End Date</th>
|
<th>End Date</th>
|
||||||
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @participant.employments.each do |employment| %>
|
<% @participant.employments.each do |employment| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= employment.worker&.name || 'No Worker Assigned' %></td>
|
<td><%= employment.worker&.name || 'No Worker Assigned' %></td>
|
||||||
<td><%= employment.start_date.strftime('%B %d, %Y') if employment.start_date.present? %></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><%= employment.end_date.strftime('%B %d, %Y') if employment.end_date.present? %></td>
|
||||||
</tr>
|
<td>
|
||||||
<% end %>
|
<%= 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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
<%= form_with(model: [@participant, @employment], url: link_worker_participant_path(@participant), method: :post, class: 'row g-3') do |form| %>
|
<%= form_with(model: [@participant, @employment], url: link_worker_participant_path(@participant), method: :post, class: 'row g-3') do |form| %>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<%= form.label :worker_id, "Select Worker", class: 'form-label' %>
|
<%= form.label :worker_id, "Select Worker", class: 'form-label' %>
|
||||||
|
|
|
@ -16,6 +16,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
resources :workers
|
resources :workers
|
||||||
resources :vendors
|
resources :vendors
|
||||||
|
resources :employments, only: [:edit, :update, :destroy]
|
||||||
resources :employers do
|
resources :employers do
|
||||||
get 'search', on: :collection
|
get 'search', on: :collection
|
||||||
end
|
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