diff --git a/app/controllers/employments_controller.rb b/app/controllers/employments_controller.rb
new file mode 100644
index 0000000..17cfccd
--- /dev/null
+++ b/app/controllers/employments_controller.rb
@@ -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
+
\ No newline at end of file
diff --git a/app/helpers/employments_helper.rb b/app/helpers/employments_helper.rb
new file mode 100644
index 0000000..55b49da
--- /dev/null
+++ b/app/helpers/employments_helper.rb
@@ -0,0 +1,2 @@
+module EmploymentsHelper
+end
diff --git a/app/views/employments/edit.html.erb b/app/views/employments/edit.html.erb
new file mode 100644
index 0000000..d122163
--- /dev/null
+++ b/app/views/employments/edit.html.erb
@@ -0,0 +1,17 @@
+
Edit Employment
+
+<%= form_with(model: @employment, url: employment_path(@employment), method: :patch) do |form| %>
+
+ <%= form.label :start_date %>
+ <%= form.date_field :start_date %>
+
+
+
+ <%= form.label :end_date %>
+ <%= form.date_field :end_date %>
+
+
+ <%= form.submit "Update Employment" %>
+<% end %>
+
+<%= link_to 'Back to Participant', participant_path(@employment.participant) %>
diff --git a/app/views/participants/show.html.erb b/app/views/participants/show.html.erb
index 3c7e949..c924ebe 100644
--- a/app/views/participants/show.html.erb
+++ b/app/views/participants/show.html.erb
@@ -68,19 +68,25 @@
Worker Name |
Start Date |
End Date |
+ Actions |
- <% @participant.employments.each do |employment| %>
-
- <%= employment.worker&.name || 'No Worker Assigned' %> |
- <%= employment.start_date.strftime('%B %d, %Y') if employment.start_date.present? %> |
- <%= employment.end_date.strftime('%B %d, %Y') if employment.end_date.present? %> |
-
- <% end %>
+ <% @participant.employments.each do |employment| %>
+
+ <%= employment.worker&.name || 'No Worker Assigned' %> |
+ <%= employment.start_date.strftime('%B %d, %Y') if employment.start_date.present? %> |
+ <%= employment.end_date.strftime('%B %d, %Y') if employment.end_date.present? %> |
+
+ <%= 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' %>
+ |
+
+ <% end %>
+
<%= form_with(model: [@participant, @employment], url: link_worker_participant_path(@participant), method: :post, class: 'row g-3') do |form| %>
<%= form.label :worker_id, "Select Worker", class: 'form-label' %>
diff --git a/config/routes.rb b/config/routes.rb
index fa584e5..bb519c8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/test/controllers/employments_controller_test.rb b/test/controllers/employments_controller_test.rb
new file mode 100644
index 0000000..f24393e
--- /dev/null
+++ b/test/controllers/employments_controller_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class EmploymentsControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end