0

我正在开发一个 ruby​​ on rails 3.2 应用程序,我需要验证一个具有嵌套属性的表单。在我的模型中,我有这个

班员
    attr_accessible :email, :password ......等
    has_many :purchase_informations, :dependent => :destroy
    Accept_nested_attributes_for :purchase_informations, :allow_destroy => true
结尾

类采购信息
    属于_to:成员
    attr_accessor :same_billing
结尾

以下是表单数据:

{ members: 
     { purchase_informations_attributes: 
          { 0: 
               { information_type: "billing",
                 title: "Mr",
                 first_name: "",
                 last_name: "",
                 cuhk_no: "",
                 organization: "",
                 address: "",
                 zip_code: "",
                 country: "Hong Kong",
                 telephone: "",
                 mobile: "", fax: "",
                 email: "asdasdasda", id: "27"
              },
           1: 
              { information_type: "shipping",
                title: "Mr",
                first_name: "",
                last_name: "",
                cuhk_no: "",
                organization: "",
                address: "",
                zip_code: "",
                country: "Hong Kong",
                telephone: "",
                mobile: "",
                fax: "",
                email: "",
                id: "28"
              }
         }
     } 
}

请帮我验证属性是否为空白。

谢谢!

4

1 回答 1

0

你好,你可以试试这个:

 accepts_nested_attributes_for : purchase_informations, :reject_if => :all_blank

或在您的表单中放置一个 :required => true 函数

<%= f.input :name, :required => true %>
于 2013-04-24T06:51:33.093 回答