Rails 3 更改错误消息 [英] Rails 3 Change Error Message
问题描述
当我的数据库 :b_name
字段为空时,出现错误消息.但是,b_name
代表企业名称,我已经在标签中说明了这一点.但是,当我收到错误消息时,它说 B name
不能为空.有什么办法可以改变它,所以当我收到错误时,它说 Business Name can't be blank
而不是 b_name cant be blank
?
I have an error message that appears when my the field for the database :b_name
is empty. However, b_name
stands for Business Name and I have made the label say that. However, when I get the error message, it says B name
cant be blank. Is there any way I can change it so when I get the error it says Business Name can't be blank
instead of b_name cant be blank
?
推荐答案
是的,其实很简单.
你应该有一个名为 config/locales/en.yml 的文件,如果不是简单地创建一个.您可以在那里添加自己的自定义名称.
You should have a file named config/locales/en.yml, if not simply create one. There you can add your own custom names.
en:
activerecord:
models:
order: "Order"
attributes:
order:
b_name: "Business Name"
这会将您的 b_name 替换为企业名称"
That will replace your b_name for "Business Name"
您在 app/models/order.rb 中的 Order 模型应如下所示:
Your Order model in app/models/order.rb should look like:
class Order < ActiveRecord::Base
validates :b_name, :presence => true
.
.
.
请让我知道它是否有效:)
Please let me know if it worked :)
这是我的应用程序运行良好的屏幕截图.
Here is an screenshot of my app working fine.
这篇关于Rails 3 更改错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!