2012-06-20 49 views
0

我试过以下在这里找到的帖子:Rails 3 Change Error Message和这里:ActiveRecord validates... custom field name但是都没有为我工作,我的数据库字段名仍显示。Rails:更改显示的错误列名

比如我得到:姓名过短(最短为1个字符)

任何想法/是否有解决此优选的方法是什么?谢谢。

下面是我用我的连接区域第一个链接的文章:

en: 
    activerecord: 
    models: 
     account:  "Account" 
    attributes: 
     order: 
     name:   "Business Name" 

这里有点我的账户模型:

validates_presence_of :name 
validates_length_of :name, :minimum => 1, :maximum => 100 

attr_accessible :name, :admin_attributes, :image 

的账户保存失败的尝试后,这里是显示从我的观点的错误代码:

​​

回答

2

我知道这是很老,但我发现这个问题1在最后只是turning to the rails guides,这让我的代码工作。

它看起来像你想的账户更改属性名称,但使用顺序:

en: 
    activerecord: 
    models: 
     account:  "Account" 
    attributes: 
     order: # Right here, this should be account 
     name:   "Business Name" 

我不相信你所需要的型号有:账户:“账户”无论是。这是为了告诉轨道,如果你想调用不同的模型,但你不这样做,所以你可以删除它。然后,属性会根据您想要更改的模型,然后是该属性。

en: 
    activerecord: 
    attributes: 
     account: 
     name: "Business name" 

我想可能都扔你过的是,它看起来很像属性属于模型,但它实际上是在另一条线路。希望这会有所帮助,尽可能晚!