Domanda

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?

È stato utile?

Soluzione

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!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top