我有这样定义的联系人信息类Mongoid错误消息:轨道/嵌套属性
class ContactInfo
include Mongoid::Document
validates_presence_of :name, :message => ' cannot be blank'
field :name, :type => String
field :address, :type => String
field :city, :type => String
field :state, :type => String
field :zip, :type => String
field :country, :type => String
embedded_in :user
end
该联络信息类是使嵌入作为嵌套属性我的用户类中:
class PortalUser
include Mongoid::Document
accepts_nested_attributes_for :contact_info
end
当我尝试保存没有名称的用户时,我收到如下错误消息:
联系信息无效
但是,这对于最终用户来说并不是非常有用,因为他或她不知道联系信息是无效的。 REAL消息应该是'名称不能为空'。但是,这个错误不会向上传播。有没有办法让user.errors中的'名称不能为空'消息,而不是'联系信息无效'的错误信息?
感谢
蒙戈有这个内置的,validates_associated。请参阅http://stackoverflow.com/questions/5078661/field-for-and-nested-form-with-mongoid – 2012-09-25 21:59:29
validates_associated只验证关联的模型,但它仍然吐出无用的错误消息。 – UrLicht 2013-09-16 21:43:53