Question

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?

Était-ce utile?

La solution

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!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top