# Model return value

**URL:** <https://www.ruby-forum.com/t/model-return-value/86252>\
**Category:** Rails\
**Created:** [February 20, 2007, 11:31pm UTC](https://www.ruby-forum.com/t/model-return-value/86252 "2007-02-20T23:31:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/8c91f0/32.png) [@ali](https://www.ruby-forum.com/u/ali)\
**Post date:** [February 20, 2007, 11:31pm UTC](https://www.ruby-forum.com/t/model-return-value/86252/1 "2007-02-20T23:31:19Z")

</div>

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
```
