diff --git a/app/controllers/participants_controller.rb b/app/controllers/participants_controller.rb index 8f27cb8..100b5bc 100644 --- a/app/controllers/participants_controller.rb +++ b/app/controllers/participants_controller.rb @@ -11,6 +11,8 @@ class ParticipantsController < ApplicationController @participant = Participant.includes(:employments).find(params[:id]) @workers = @participant.workers # Fetch associated workers @employment = Employment.new # Initialize a new Employment object + @participant = Participant.includes(employments: :worker).find(params[:id]) + @employments = @participant.employments.joins(:worker).order('workers.last_name') end diff --git a/app/controllers/workers_controller.rb b/app/controllers/workers_controller.rb index 2fe857c..1c37edc 100644 --- a/app/controllers/workers_controller.rb +++ b/app/controllers/workers_controller.rb @@ -41,7 +41,8 @@ class WorkersController < ApplicationController private def worker_params - params.require(:worker).permit(:name, :address, :phone, :email, :dob, :ssn, :gender) + params.require(:worker).permit(:first_name, :last_name, :address, :phone, :email, :dob, :ssn, :gender) end + end \ No newline at end of file diff --git a/app/models/worker.rb b/app/models/worker.rb index 930f3c8..8786d42 100644 --- a/app/models/worker.rb +++ b/app/models/worker.rb @@ -5,4 +5,13 @@ class Worker < ApplicationRecord # Many-to-many relationship with Employers through Participants has_many :employers, through: :participants + + # Validations + validates :first_name, presence: true + validates :last_name, presence: true + + # Method to return the full name of the worker + def full_name + "#{first_name} #{last_name}" + end end diff --git a/app/views/employments/edit.html.erb b/app/views/employments/edit.html.erb index d122163..4486de5 100644 --- a/app/views/employments/edit.html.erb +++ b/app/views/employments/edit.html.erb @@ -14,4 +14,6 @@ <%= form.submit "Update Employment" %> <% end %> -<%= link_to 'Back to Participant', participant_path(@employment.participant) %> +<%= link_to 'Delete Employment', employment_path(@employment), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %> + +<%= link_to 'Back to Participant', participant_path(@employment.participant), class: 'btn btn-secondary' %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ed08b44..e3e2c3b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,7 +10,6 @@ <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'rails-ujs', 'data-turbolinks-track': 'reload' %> -
@@ -44,9 +43,7 @@ <% end %> - - - +