[英]Updating the attributes in the rails errors
我正在尋找使用人性化屬性名稱發送的導軌更新的模型錯誤哈希。 例如,對於名為Foo
的模型。 我有一個名為foo_nm
的屬性。 假設@foo
是Foo類的對象,我在執行@foo.errors
foo.errors時希望轉換為foo_name。
{"foo_nm"=>["can't be blank"]}
到目前為止,我嘗試通過以下方式擴展human_attribute_name
HUMANIZED_ATTRIBUTES = {
:foo_nm => "foo_name"
}
def self.human_attribute_name(attr, options={})
HUMANIZED_ATTRIBUTES[attr.to_sym] || super
end
但這似乎並未修改錯誤哈希。 關於如何更新錯誤哈希的任何想法將不勝感激
您不能在語言環境文件中執行此操作嗎?
# config/locales/en.yml
en:
hello: "Hello world"
activerecord:
models:
foo: "Foo"
attributes:
foo_nm: "foo_name"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.