Ruby on rails 3.2 RubyonRails3.2接受嵌套的属性验证

Ruby on rails 3.2 RubyonRails3.2接受嵌套的属性验证,ruby-on-rails-3.2,nested-forms,nested-attributes,Ruby On Rails 3.2,Nested Forms,Nested Attributes,我正在开发一个RubyonRails3.2应用程序,我需要验证一个具有嵌套属性的表单。在我的模型中,我有这个 class Member attr_accessible :email, :password.............etc has_many :purchase_informations, :dependent => :destroy accepts_nested_attributes_for :purchase_informations, :allow_de

我正在开发一个RubyonRails3.2应用程序,我需要验证一个具有嵌套属性的表单。在我的模型中,我有这个

class Member attr_accessible :email, :password.............etc has_many :purchase_informations, :dependent => :destroy accepts_nested_attributes_for :purchase_informations, :allow_destroy => true end class PurchaseInformation belongs_to :member attr_accessor :same_billing end 请帮助我验证属性是否为空

谢谢

您好,您可以试试这个:

 accepts_nested_attributes_for : purchase_informations, :reject_if => :all_blank
或者在表单中放入:required=>true函数

<%= f.input :name, :required => true %>
true%>

你好,艾伦。感谢您的见解,不幸的是,上面的方法不是一个选项,因为我需要遍历每个值来检查是否有空值。只有当所有值都为空时,它才会工作。对于输入字段上的必需属性,这在HTML5上使用,并非所有浏览器都支持这一点。非常感谢。请尝试以下操作:这将验证特定列的有效性,并验证是否存在嵌套属性的名称:接受\u嵌套的\u属性\u for:purchase\u informations,:reject\u if=>lambda{a | a[:name].blank?}
<%= f.input :name, :required => true %>