Forum: Ruby on Rails Model return value

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
64e445650d4b18f643e227fa64146483?d=identicon&s=25 Ali (Guest)
on 2007-02-20 23:31
(Received via mailing list)
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
This topic is locked and can not be replied to.