2010-10-04 61 views
1
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 

你怎麼了如何在Rails 3中本地化ActiveModel錯誤消息?

  1. 本地化的錯誤消息(S):用於FIRST_NAME
  2. 本地化的錯誤消息(S):姓氏
+0

類似問題http://stackoverflow.com/questions/3501019/how-to-localize-the-active-record-error-messages – AMIT 2010-10-05 19:03:31

回答

1

您使用的模型沒有數據庫, 對?你必須加載ActiveModel用的翻譯類這樣的擴展類:

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