ruby on rails - Cannot validate empty nested fields -


i have nested form creating members inside enrollment

class enrollment < activerecord::base   has_many :atendees, dependent: :destroy   accepts_nested_attributes_for :atendees, reject_if: :all_blank, allow_destroy: true end 

and validations on member model.

if submit enrollment form blank member fields, enrollment saves empty members array.

if input member field , submit it, member model validations take action.

any ideas why happening?

i tried checking 1 column:

  accepts_nested_attributes_for :atendees, , reject_if: proc { |attributes| attributes['first_name'].blank? }, allow_destroy: true 

to me seems expected behaviour. reject_if should 'silently' ignore fields fail meet condition. if removed reject_if clause usual model validation should occur member instances.

if not, can use validates_associated in enrollment model

validates_associated :atendees 

Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -