html - Rails Show Age in View based Born Date -
i have problem show age in view rails
i think solve:
show.html.slim `=@people.date_born - date.today / 365,25` `end`
what need do?
it's order of operations thing, syntax displayed funny. ignoring unnecessary quotes:
= ((date.today - @person.date_born) / 365).to_i
first, since today greater date date of birth, want first avoid negative number. need wrap in parens subtraction first, , divide, , legibility, change integer.
Comments
Post a Comment