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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -