取得するにはmessages
を使う
つまりインスタンス.errors.messagse
で取得できる。
例
例えばコンソールから
>> p = Person.new
# => #<Person id: nil, name: nil>
>> p.errors.messages
# => {}
>> p.valid? ←手動でバリデーション実行
# => false
>> p.errors.messages ←バリデーションでfalseになったので、中にエラーが代入される
# => {name:["空欄にはできません"]}
みたいになる
*Personモデルがnameカラム持ってて、バリデーションに presence: true とかしてた場合。