我有一个这样定义的联系信息类:
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 中获取“名称不能为空”消息而不是“联系信息无效”错误消息?
谢谢