本文介绍了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版本是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 18:53