Answer the question
In order to leave comments, you need to log in
How to display user age in rails?
I filed the age of the users, now I can’t figure out how to add the correct declination of “years” “years” “year” to them at the end
User.rb
def age
now = Time.now.utc.to_date
now.year - birthday.year - (birthday.to_date.change(:year => now.year) > now ? 1 : 0)
end
<%= @user.age %>
Answer the question
In order to leave comments, you need to log in
Rails has a helper for this, but it doesn't work properly with Russian. Look aside https://github.com/yaroslav/russian/
there is an example
Russian::pluralize
Russian::p
Russian.p(1, "thing", "things", "things")
=> "thing"
Russian .p(2, "thing", "things", "things")
=> "things"
Russian.p(10, "thing", "things", "things")
=> "things"
Russian.p(3.14 , "thing", "things", "things", "things") # the last option is used for fractional values
=> "things"
in your case will be something like <%= @user.age Russian.p(@user. age, "..
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question