LoginSignup
1
0

More than 5 years have passed since last update.

Validation messageをいじる

Posted at

Railsのフォームでfields_forとかを使っているとvalidationメッセージがひどいことになった。

Message message bodies body can't be blank

ユーザフレンドリーなメッセージにするにはconfig/locales/en.ymlをいじればいいっぽい。

config/locales/en.yml
en:
  activerecord:
    attributes:
      message:
        message_bodies:
          body: "Message"
    errors:
      models:
        message_body:
          attributes:
            body:
              blank: "has to be filled"

参考: stackoverflow.com

:blank 以外に何が使えるかは本家に聞くのが一番。

しかし、この階層構造はどう決まってるんだ?

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