문제

I'm outputting Date attributes with the following method

@project.end_date.strftime("%b %Y")

What is the simplest way to localize this date such that it displays in the locale defined in application.rb?

도움이 되었습니까?

해결책

The simplest way to do this is to use Rails' #l helper method like so:

l @project.end_date

You can also use a format you defined in locales .yml file:

l @project.end_date, format: :short

# config/locales/pirate.yml
pirate:
  time:
    formats:
      short: "arrrround %H'ish"

The Rails guide covers this. Hope that helps!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top