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?
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?
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.