简体   繁体   中英

Is there a way to enforce reject_if for accep accepts_nested_attributes_for only on create?

I have something like

accepts_nested_attributes_for :questions,  :allow_destroy => true, :reject_if => lambda {|q| q[:body].blank?}

The problem is that if I want to update questions and they are empty they are rejected which means they won't be validated.

Is there a way to enforce that the reject only happens on create and not update?

Perhaps a check whether the :id value is blank? If it's blank then you know that it is a create.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM