-1

I have a problem to show age in a view with rails

i think this to solve:

 show.html.slim    
    `=@people.date_born - Date.today / 365,25`  
    `end`  

What i need to do?

1 Answers1

1

It's probably just an order of operations thing, but your syntax was displayed funny. Ignoring the unnecessary quotes:

= ((Date.today - @person.date_born) / 365).to_i

First, since today is a greater date than the date of birth, you want it first to avoid a negative number. You need to wrap it in parens to do the subtraction first, and then divide, and for legibility, change it back to an integer.

DGM
  • 26,629
  • 7
  • 58
  • 79