Model return value

Hello all,

I’ve posted regarding this topic previously…

I’m using a case statement to calculate age based on the age unit
chosen by the user. It is working great inside the web application,
but for any age less than a year, it saves a zero to the database. My
age field in the DB is an int, so I can’t figure out why it is doing
the correct calculation in the model, but then returning a zero in the
save? The only thing I’m doing different is on the year calculation,
so maybe I need some variation of that for the rest of the units? As
always, any and all help and suggestions are appreciated!!

Code:

unit = read_attribute(:ageunit_id)
m = read_attribute(:dob)
if not m.nil?
if not dod.nil?
seconds = dod - m
s = seconds.to_i

          case unit

          # minutes
          when 316
             minutes = s / 60

          # hours
          when 315
             minutes = s / 60
             hours = min / 60

          # days
          when 314
             minutes = s / 60
             hours = minutes / 60
             days = hours / 24

          # months
          when 313
             minutes = s / 60
             hours = minutes / 60
             days = hours / 24
             months = days / 30

          # years
          when 312
             minutes = s / 60
             hours = minutes / 60
             days = hours / 24
             months = days / 30
             years = dod.year - dob.year-(dob.to_time.change(:year

=> dod.year) > dod ? 1 : 0)

          end