avosalmonのブログ

プログラミングやWebデザイン、DTMについて調べたことをメモってます。プログラマー兼ベーシストです。

【Rails】date_selectで"undefined method for translation missing ja date order string"

Viewで下記のようにdate_selectを使うと、i18nの日本語設定が足りずエラーが出た。

<%= f.date_select(:birthday, {:use_month_numbers=>true, :start_year=>1930, :end_year => Time.now.year, :default =>'1990-1-1'.to_date}, {:class => ["form-control", "inline_date_select"]})  %>


こんなエラーが出た
undefined method for translation missing ja date order string


config/locales/ja.ymlを作り、以下を記入することで解決。

ja:
  date:
    formats:
      default: "%Y/%m/%d"
      short: "%m/%d"
      long: "%Y年%m月%d日(%a)"
    day_names: ["日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"]
    abbr_day_names: ["日", "月", "火", "水", "木", "金", "土"]
    month_names: ["~", "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
    abbr_month_names: ["~", "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
    order: ["year", "month", "day"]
  time:
    formats:
      default: "%Y/%m/%d %H:%M:%S"
      short: "%y/%m/%d %H:%M"
      long: "%Y年%m月%d日(%a) %H時%M分%S秒 %Z"
    am: "午前"
    pm: "午後"


参考記事
transitive.info - Rails 4 と Ruby 2.0 を使う (3)