如果除一个字段之外的所有其他字段均为空白,是否可以使用reject_if拒绝嵌套资源? [英] Can reject_if be used to reject a nested resource if all fields except one is blank?

查看:64
本文介绍了如果除一个字段之外的所有其他字段均为空白,是否可以使用reject_if拒绝嵌套资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以拥有:

accepts_nested_attributes_for :foo, :reject_if => proc { |a| a[:bar].blank? }

有没有办法像这样说

accepts_nested_attributes_for :foo, :reject_if => blah[:bar].blank? and flah[:bar].blank?

accepts_nested_attributes_for :foo, :reject_if => all fields except record_date.blank?

谢谢

推荐答案

对此我有些迟了,但是您可以这样做:

I'm a bit late on this, but you can do :

accepts_nested_attributes_for :foo, 
                               reject_if: ->(attributes){ 
                                 attributes.except(:key).values.all?( &:blank? ) 
                               }

这篇关于如果除一个字段之外的所有其他字段均为空白,是否可以使用reject_if拒绝嵌套资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆