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?

Was it helpful?

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top