ruby on rails 4 - nested form objects fails validation complaining of missing parent_id -
ruby on rails 4 - nested form objects fails validation complaining of missing parent_id -
i utilize simple_form. when using rails accepts_nested_attributes_for, form fails validation complaining nested attributes validation failed because id of parent object can't blank (validates_presence_of).
i know parent object id beingness submitted, because if remove validation form submits, , kid record valid. so, validations looking @ params before parent id associated child...and therefor failing. seems strange. why rails running validation @ stage in form submission before parent of nested attributes correctly associated?
is there rails way handling scenario?
just found reply in rails docs. here's example, using inverse_of:
class fellow member < activerecord::base has_many :posts, inverse_of: :member accepts_nested_attributes_for :posts end class post < activerecord::base belongs_to :member, inverse_of: :posts validates_presence_of :member end validation ruby-on-rails-4 simple-form nested-attributes
Comments
Post a Comment