سؤال

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