My Job model has id and percentage fields (among others).
percentage may be nil.
I would like to set a default percentage here:
class JobsController
def new
...
@job.percentage = <what should be here?>
...
end
end
It should be calculated like this:
- Take the percentage of the latest job (a job with max id), which percentage isn't
nil. - If there are no jobs, or all jobs percentage is
nil, it should be 23.
What is the easiest method to calculate this ?