2
我越來越被reject_if拒絕。的Rails 3 - reject_if PROC不要再追空字段
的Item模型的has_many變體,與該模型還接受嵌套屬性:
accepts_nested_attributes_for :variants, :allow_destroy => :true,
:reject_if => :all_blank
當我提交,它張貼以下參數:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"66areo4waM82H66771RkUD/Zt3rrp8Hgk/mwOqV42YI=", "item"=>{"name"=>"Dans", "body"=>"adsdsa", "visible"=>"1", "sellable"=>"0", "variants_attributes"=>{"0"=>{"name"=>"", "price"=>"", "qty"=>"", "sku"=>"", "_destroy"=>"false"}}}, "commit"=>"Save Item", "id"=>"6"}
爲了參考,所述控制器:
def edit
@item = Item.find(params[:id])
@item.variants.build
變體屬性是空白的,但他們沒有被採用t拒絕他的物品模型。因此,所有的驗證才能通過,使之無法保存。有任何想法嗎?