2010-08-26 118 views

回答

2

使用本地化來設置屬性的「英文」名稱。您可以設置單數和複數名:

en: 
    activerecord: 
    attributes: 
     product: 
     unit: 
      one: Unit price 
      other: Unit prices 
+0

似乎並不適合我。 我還沒有在本地化工作,有沒有什麼我需要做之前,這將工作? – fivetwentysix 2010-08-26 07:23:32

+1

修復了我的答案:我的答案是型號名稱,而不是屬性名稱。 – 2010-08-26 07:50:55

+1

@Andrew Vit這是錯誤的答案。在具有屬性名稱的行之前,需要一行包含模型名稱的行。請參閱示例如何解決同一問題:http://stackoverflow.com/questions/808547/fully-custom-validation-error-message-with-rails – 2012-02-18 15:01:50

1

我不知道如何更改列名,但下面是一個工作的解決方法

在模型中創建一個名爲UNIT_PRICE

虛擬屬性

像這樣

attr_accessor :unit_price 

validates_presence_of :unit_price, :message => "This is a custom validation message" 

def before_validation 
    self.unit_price = self.unit 
end 

歡呼

sameera