什么是Rails3 版本的errors.add_to_base? [英] What is the Rails3 version of errors.add_to_base?

查看:14
本文介绍了什么是Rails3 版本的errors.add_to_base?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Rails 3 中编写自定义验证,但遵循 这个例子 我明白了:

I want to write a custom validation in Rails 3, but following this example I get:

'ActiveModel::DeprecatedErrorMethods.add_to_base' call is deprecated in Rails 3.0

rails3 版本是什么:

What is the rails3 version of:

def validate
   errors.add_to_base "If you are attaching a file you must enter a label for it" if !attachment.blank? and attachment_label.blank?
end

推荐答案

这应该适用于 rails 3.1.3:

This should work in rails 3.1.3:

errors.add :base, "message"

这篇关于什么是Rails3 版本的errors.add_to_base?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆