close
ActiveRecord的欄位驗證訊息是英文,要改成其它語言,可以覆寫ActiveRecord:: Errors.default_error_messages定義的訊息,如此,就不需要在每個用到validates_*_of的地方加上: message參數。直接在environment.rb加入:
ActiveRecord::Errors.default_error_messages = { :inclusion => "不是選項之一", :exclusion => "已被保留", :invalid => "是無效的", :confirmation => "與確認值不符", :accepted => "必需被接受", :empty => "不能是空的", :blank => "不能是空白", :too_long => "太長(最多%d個字)", :too_short => "太短(至少%d個字)", :wrong_length => "長度不對(必須%d個字)", :taken => "已被使用", :not_a_number => "不是數字" }
全站熱搜