我想在 Rails 3 中编写自定义验证,但是以下这个例子 http://paulsturgess.co.uk/articles/show/33-how-to-write-custom-validation-in-ruby-on-rails I get:
'ActiveModel::DeprecatedErrorMethods.add_to_base' call is deprecated in Rails 3.0
Rails3 版本是什么:
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:
errors.add :base, "message"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)