2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails datetime_selectのエラー対応

Posted at

datetime_selectエラーがでた

new.html.erb
<div>新規プロジェクト</div>
<%= form_for(@project) do |f| %>
  <div><%= f.label :title %>
  <div><%= f.text_field :title %></div>
  <div><%= f.label :state %></div>
  <div><%= f.text_field :state %></div>
  <div><%= f.label :limit_date %></div>
  <div><%= f.datetime_select :released_at,
              start_year: 2000, end_year: Time.current.year + 1,
              use_month_numbers: true %></div>
  <div><%= f.submit %></div>
<% end %>

上記のnewのviewを実装後にlocalhost:3000/projects/newをリクエストしたら下記のエラーが出た。

ターミナル
ActionView::Template::Error (undefined method `map' for "translation missing: ja.date.order":String
Did you mean?  tap):
     5:   <div><%= f.label :state %></div>
     6:   <div><%= f.text_field :state %></div>
     7:   <div><%= f.label :limit_date %></div>
     8:   <div><%= f.datetime_select :released_at,
     9:               start_year: 2000, end_year: Time.current.year + 1,
    10:               use_month_numbers: true %></div>
    11:   <div><%= f.submit %></div>

解決策

ja.ymlを作成すると解決する

config/locales/ja.yml
ja:
  date:
    order:
      - :year
      - :month
      - :day

もしくはi18nを無効化しても良いということが調べたら載ってました。

参考: https://jangajan.com/blog/2014/09/12/perfect-rails-i18n/

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?