如何在Rails 3中本地化ActiveModel错误消息?

时间:2010-10-04 21:50:31

标签: validation localization ruby-on-rails-3 activemodel

class User
  include ActiveModel::Validations
  validates_presense_of :first_name
  validates_length_of :last_name, :in => 3..20, :too_long => "pick a shorter last name", :too_short => "pick a longer last name"

  attr_accessor :first_name, :last_name
end

你好吗

  1. 本地化错误消息:first_name
  2. 本地化错误消息:last_name

1 个答案:

答案 0 :(得分:1)

你正在使用没有数据库的模型,对吧?您必须使用ActiveModel的翻译类扩展您的类,如下所示:

class User
  [...]
  extend ActiveModel::Translation
  [...]