新手问题 validates 的错误提示该在哪里改?

coooldfarmer · September 09, 2015 · Last by liwei78 replied at September 09, 2015 · 1395 hits

比如

validates :name, length: {maximum: 20}

超过 20 字时的错误提示信息,该在哪里改?

额,查到了。 validates :password, presence: { if: :password_required?, message: 'is forgotten.' }, confirmation: true

validates :name, length: {maximum: 20}, message: "....."

不过太久不这么写了。应该用 Rails 的 I18n。这里 有一些语言包,使用这个方法加载他们:

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**/*.{rb,yml}').to_s]
config.i18n.default_locale = :"zh-CN"
You need to Sign in before reply, if you don't have an account, please Sign up first.