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 回调中的黑客删除空记录。忽略这些空白对象最合理的方法是什么?
我不需要验证和错误,只是静默删除/忽略。
i have
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
I have a dynamic form where you press '+' to add new textareas for creating new favorites.
What i want to do is ignore the blank ones, I find this harder to sort through in the update controller than a non nested attribute.
What i have temporarily is a hack in the after_save callback deleting the empty records. Whats the most rails way to ignore these blank objects?
I dont want validation and errors, just a silent deletion/ignore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个内置的验证:
There is a built-in validation: