0
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?

学習28日目

Posted at

今日学んだこと

エラーメッセージの日本語化

内容

準備

gemの導入
(Gemfile)

gem 'rails-i18n'

(ターミナル)

$ bundle install

(config/application.rb)

config.i18n.default_locale = :ja

記述例

※ 自分のカラム名等によって適切に設定すること
※ 追記する部分のみ抜粋して示している

(config/locales/ja.yml)

ja:
  activerecord:
    attributes:
      hoge:
        name: ホゲネーム
        text: ホゲテキスト

(app/models/hoge.rb)

validates :name, presence: true, message: "を入力してください"
validates :text, presence: true, message: "を入力してください"

感想

ymlファイルはインデントにより入れ子構造を判断しているため、適切にインデントを入れないと正しく反映されず苦労した。(全角スペースを入力できないよう設定を見直した)

0
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
0
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?