RecordActive中default_errors_messages的改变

正在看railsspace_building_a_social_networking_website_with_ruby_on_rails一书,Rails_Space的测试代码,在测试时发现用下列验证输入信息过长的错误。在Rails2.2.2中发生错误。
error_messages = ActiveRecord::Errors.default_error_messages
sprintf(error_messages[:too_long], length)
经查看代码,在rails-2.0前,可以把default_error_messages中%d替换成数字。
在Rails2.2.2中,default_error_messages定义发生了变化,不能把{{counter}}提换成数字。可以在script/console 中,通过输入ActiveRecord::Errors.default_error_messages查看详细内容。
2.0以前,在validations.rb中
@@default_error_messages = {
:inclusion => "is not included in the list",
:exclusion => "is reserved",
:invalid => "is invalid",
:confirmation => "doesn't match confirmation",
:accepted => "must be accepted",
:empty => "can't be empty",
:blank => "can't be blank",
:too_long => "is too long (maximum is %d characters)",
:too_short => "is too short (minimum is %d characters)",
:wrong_length => "is the wrong length (should be %d characters)",
:taken => "has already been taken",
:not_a_number => "is not a number",
:greater_than => "must be greater than %d",
:greater_than_or_equal_to => "must be greater than or equal to %d",
:equal_to => "must be equal to %d",
:less_than => "must be less than %d",
:less_than_or_equal_to => "must be less than or equal to %d",
:odd => "must be odd",
:even => "must be even"
}
2.2.2,在validations.rb中
def default_error_messages
ActiveSupport::Deprecation.warn("ActiveRecord::Errors.default_error_messages
has been deprecated. Please use
I18n.translate('activerecord.errors.messages').")
I18n.translate 'activerecord.errors.messages'
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值