10
我有accepts_nested_attributes_for忽略空白值
class Profile
has_many :favorite_books, :dependent => :destroy
has_many :favorite_quotes, :dependent => :destroy
accepts_nested_attributes_for :favorite_books, :allow_destroy => true
accepts_nested_attributes_for :favorite_quotes, :allow_destroy => true
end
我已經在按「+」添加新的文字區域用於創建新的收藏夾一個動態的形式。 我想要做的是忽略空白的,我發現這比在非嵌套屬性中更難以在更新控制器中進行排序。
我暫時是在after_save回調中刪除空記錄的黑客。什麼是最忽略這些空白對象的方式?
我不想驗證和錯誤,只是一個沉默的刪除/忽略。
大尖apneadiving,謝謝!我發現這一點(對於其他人閱讀)「你也可以設置:reject_if proc默默地忽略任何新的記錄哈希,如果它們不能通過你的標準。例如,前面的例子可以改寫爲:」 - http: //api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html – Mike 2011-02-10 23:24:17