The thing with validating presence of parent like this is timing !! actually the Shift
is not yet saved so when trying to create nested ranges
it won't find parent Shift
in database.
I found this workaround here
class Shift < ActiveRecord::Base
attr_accessible :ranges_attributes
has_many :ranges, :inverse_of => :shift
accepts_nested_attributes_for :ranges, allow_destroy: true
end
and i quote (with minor modifications) from the same source:
With this option rails won't try to get parent from database when child is validated. The parent will be got from memory. If you don't familiar with this option I strongly recommend you to read an official rails guide