ruby-on-rails – acceptable_nested_attributes_for忽略空白值
发布时间:2020-12-16 22:41:01 所属栏目:百科 来源:网络整理
导读:我有 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_des
我有
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回调中删除空记录的一个黑客.什么是最可靠的方式来忽略这些空白对象? 我不想要验证和错误,只是一个静默删除/忽略. 解决方法
有一个内置的验证:
:reject_if => lambda { |c| c[:name].blank? }, (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |