I’ve been stuck trying to get a has_many :through relationship working
my Rails application.
I have a Employee model, a Timesheet model and a Payment model.
The Employee has many Timesheets and a Timesheet has many Employees.
The Timesheet table will contain its ID and a Date. the Payment model is
the join table, it belongs to a Employee and a Timesheet, it also has an
extra field called hours_worked.
See below models
class Timesheet < ActiveRecord::Base
has_many :employees, :through => :paymentsend
class Employee < ActiveRecord::Base
has_many :timesheets, :through => :payments end
class Payment < ActiveRecord::Base
I want to create a form where I can create a new Timesheet by chosing a
date, listing all Employees and allowing me to enter the hours_worked
for each employee.
Once I submit the form, it should create a new Timesheet, and create a
Payment for each employee with each employee’s hours_worked for that
I hope this makes sense and I can get your help!!