diff --git a/app/models/employer.rb b/app/models/employer.rb index 9da1636..1968db9 100644 --- a/app/models/employer.rb +++ b/app/models/employer.rb @@ -10,4 +10,7 @@ class Employer < ApplicationRecord has_many :workers, through: :direct_participants # Other methods... + def full_name + "#{first_name} #{last_name}" + end end diff --git a/app/models/worker.rb b/app/models/worker.rb index 66ce65a..f124b89 100644 --- a/app/models/worker.rb +++ b/app/models/worker.rb @@ -6,7 +6,8 @@ class Worker < ApplicationRecord has_many :participants, through: :employments # Many-to-many relationship with Employers through Participants - has_many :employers, through: :participants + has_many :employers, through: :participants, source: :employer + has_many :employer_records, through: :participants # Validations validates :first_name, presence: true diff --git a/app/views/workers/show.html.erb b/app/views/workers/show.html.erb index f6bac94..4af92aa 100644 --- a/app/views/workers/show.html.erb +++ b/app/views/workers/show.html.erb @@ -114,6 +114,43 @@ <% end %> +
Employer Name | +Start Date | +End Date | +Actions | +
---|---|---|---|
<%= employer_record.employer.full_name %> | +<%= employer_record.start_date.strftime('%B %d, %Y') if employer_record.start_date %> | +<%= employer_record.end_date.strftime('%B %d, %Y') if employer_record.end_date %> | ++ <%= link_to 'View', employer_path(employer_record.employer), class: 'btn btn-sm btn-secondary' %> + <%= link_to 'Edit', edit_employer_record_path(employer_record), class: 'btn btn-sm btn-info' %> + | +
No linked employers.
+ <% end %> +