我有
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
我有一个动态表单,您可以在其中按“+”添加新的文本区域以创建新的收藏夹。 我想要做的是忽略空白的,我发现这比非嵌套属性更难在更新 Controller 中排序。
我暂时拥有的是在 after_save 回调中删除空记录的黑客攻击。忽略这些空白对象的最有效方法是什么?
我不想要验证和错误,只是静默删除/忽略。
最佳答案
有一个内置的验证:
:reject_if => lambda { |c| c[:name].blank? },
关于ruby-on-rails - accepts_nested_attributes_for 忽略空白值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4963769/