title: Unable to create associated/ nested child record with "accepts_nested_attributes_for"
body: <p>I get the following error on trying to create associated child record through parent using "accepts_nested_attributes_for":</p>
  
  <blockquote>
    <p>ActiveRecord::RecordInvalid (Validation failed: Survey question details survey can't be blank, Survey question details activity detail must exist):</p>
  </blockquote>
  
  <p>Wondering if I missing any piece for creation of child record automatically?</p>
  
  <p>Sample input: (first 4 keys in the below input are merged into the params hash before saving)</p>
  
  <blockquote>
    <p>{:organization_id=>"hardcoded", :activity_library_type=>0, :created_by=>"hardcoded", :updated_by=>"hardcoded", "activity_name"=>"s-s-28", "description"=>"", "content_path_url"=>"", "activity_status"=>0, "activity_type"=>4, "group"=>"group", "code_level"=>"code", "topic"=>"topic", "solution"=>"solution", "survey_question_details_attributes"=>[{"question"=>"Question1", "order"=>1, "question_type"=>0}]}</p>
  </blockquote>
  
  <p>Parameters:</p>
  
  <blockquote>
    <p>params.require(:activity_detail).permit(:activity_name, :description,
    :content_path_url, :activity_status,:activity_type,:group, :code_level, :topic, :solution, :duration_seconds, :survey_question_details_attributes => [:id, :question, :order, :question_type,:_destroy])</p>
  </blockquote>
  
  <p>Below is the controller and the models (Each activity contains many question ):</p>
  
  <pre><code>class ActivityController &lt; ApplicationController
  def create
      # Merged additional_attributes hash to content_params recieved from front end (first 4 keys mentioned above in sample input)
      full_activity_details_record = additional_attributes.merge(content_params)
      response = ActivityDetail.create(full_activity_details_record)
    end
  end
  
  class ActivityDetail &lt; ApplicationRecord
    has_many :survey_question_details, dependent: :destroy, foreign_key: :survey_id
    accepts_nested_attributes_for :survey_question_details
  
    validates :activity_name, :organization_id,
              :activity_library_type, :activity_status, :activity_type,
              :created_by, :updated_by, presence: true
    validates :activity_name, uniqueness: { case_sensitive: false }, length: { maximum: 55 }
    validates :description, length: { maximum: 160 }
  
  end
  
  
  class SurveyQuestionDetail &lt; ApplicationRecord
    belongs_to :activity_detail, foreign_key: :survey_id
  
    validates :question, :survey_id, :question_type, :order, presence: true
    default_scope { order(:order) }
  end
  
  </code></pre>