Skip to content

Instantly share code, notes, and snippets.

@hamajyotan
Created May 24, 2019 00:06
Show Gist options
  • Save hamajyotan/48ccb972e7cbfd2d67e04488bf3c70b5 to your computer and use it in GitHub Desktop.
Save hamajyotan/48ccb972e7cbfd2d67e04488bf3c70b5 to your computer and use it in GitHub Desktop.
activerecord validation error i18n
# app/models/hoge.rb
class Hoge < ApplicationRecord
validates :foo, presence: true
validates :bar, presence: true
validates :foo, uniqueness: { scope: [:bar] }
end
# config/locales/ja.yml
---
ja:
activerecord:
errors:
models:
hoge:
attributes:
foo:
taken: "foo と bar で一意でないとあかんねん"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment