This is my first rails program and Iâ??m having trouble figuring out how
to show rows on the page when there may not be rows in the database.
There are 3 tables, employees, cost_codes and timesheet, I will simplify
them when describing them later on.
When an employee logs in, I would like to pull up their timesheet, which
should consist of one row per cost code. So timesheet would look a
little like:
(timesheets)
Name, Cost Code, Ending Date, M,T,W,Th,F
Bob, 11701, â??7-15-2006â??, 8,8,0,0,0
Bob, 11704, â??7-15-2006â??, 0,0,8,8,4
Bob, 55702, â??7-15-2006â??, 0,0,0,0,4
(Cost Codes)
Code, Description, Default
11701, â??Programmingâ??, 1
11702, â??Researchâ??, 1
11703, â??User Studiesâ??, 1
11704, â??Documentationâ??, 1
11705, â??Vacationâ??, 1
55701, â??Onsite Trainingâ??,0
55702, â??Client Relationsâ??,0
55703, â??Conferencesâ??,0
Where part of my problem is when the data entry form is displayed to the
user, all of the default rows should be shown regardless of there being
a timesheet row, plus any optional rows. Also, instead of just listing
the default rows, I would want to substitue any values currently in the
timesheet table.
So the user should see a form something like this: [ ] are textboxes
Programming [ 8 ] [ 8 ] [ 0 ] [ 0 ] [ 0 ]
Research [ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ]
User Studies [ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ]
Documentation [ 0 ] [ 0 ] [ 8 ] [ 8 ] [ 4 ]
Vacation [ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ]
Client Relations [ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 4 ]
And a second question are my relations correct?
Employee has_many Timesheets
Timesheet belongs_to Employee
Timesheet has_many CostCodes *
(Should this be a has_one instead of many?)
CostCode belongs_to Timesheet
Thanks for any help or suggestions.
Bob