title: Complex Rails form with Nested Attributes (Rails 5)
body: <p>I have a form, that is saving the main attribute, but not its nested attributes. I have dug into a lot of documents, and seem to be doing things correctly, but still get an error that my nested attributes &quot;must exist&quot;.</p>
  <p>My interview attributes are saving correctly to the database, but my logs show &quot;Unpermitted parameters: student, parents&quot;</p>
  <p>My code is modified for brevity, but I will still try to be thorough enough to get some direction as to what might be going wrong ...</p>
  <p><strong>Models</strong> (which I include accepts_nested_attributes for :student, :parents)</p>
  <p>:student is singular since it has a has_one relationship</p>
  <p>:parents is plural since it has a has_many relationship</p>
  <pre><code>class Interview &lt; ApplicationRecord
    has_one :student
    has_many :parents
  
    accepts_nested_attributes_for :student, :parents
  end
  
  class Student &lt; ApplicationRecord
    belongs_to :interview
  end
  
  class Parent &lt; ApplicationRecord
    belongs_to :interview
  end
  </code></pre>
  <p><strong>Controller</strong></p>
  <pre><code>class InterviewsController &lt; ApplicationController
  
    def index
      @interviews = Interview.all
    end
  
    def show
      @interview = Interview.find(params[:id])
    end
  
    def new
      @interview = Interview.new
      @interview.build_student
      2.times { @interview.parents.build }
    end
  
    def create
      @interview = Interview.new(interview_params)
  
      if @interview.save
        redirect_to @interview
      else
        render :action =&gt; 'new'
      end
    end
  
  
  
    private
  
      def interview_params
        params.require(:interview).permit(:date_today, :date_contact, :purpose_of_call, :problems_start_date, :cause, :violence, :running_away, :police_contact, :suicide, :self_harm, :other_info, :testing, :hospitalization, :medications, :school_problems, :teacher_relationships, :parent_goals, :notes,
        student_attributes: [:id, :name, :age, :height, :weight, :dob, :interview_id],
        parents_attributes: [:id, :name, :relationship, :parentage, :address, :phone_home, :phone_work, :phone_mobile, :phone_mobile, :email, :employer, :notes, :interview_id] )
      end
  
  end
  </code></pre>
  <p><strong>Form</strong> (important bits)</p>
  <pre><code>&lt;%= form_for(@interview) do |f| %&gt;
  
      &lt;p class=&quot;inline&quot;&gt;
        &lt;%= f.label :date_today, 'Today\'s Date' %&gt;
        &lt;%= f.date_select(:date_today, :order =&gt; [:month, :day, :year], :start_year =&gt; 2000, :end_year =&gt; Date.today.year) %&gt;
      &lt;/p&gt;
  
      &lt;p class=&quot;inline float_right&quot;&gt;
        &lt;%= f.label :date_contact, 'Initial Contact' %&gt;
        &lt;%= f.date_select(:date_contact, :order =&gt; [:month, :day, :year], :start_year =&gt; 2000, :end_year =&gt; Date.today.year) %&gt;
      &lt;/p&gt;
  
      &lt;%= f.fields_for :student do |student_form| %&gt;
        &lt;p&gt;&lt;%= student_form.text_field :name, placeholder: 'Name' %&gt;&lt;/p&gt;
  
         &lt;p class=&quot;inline&quot;&gt;
           &lt;%= student_form.label :age %&gt;
           &lt;%= student_form.text_field :age %&gt;
         &lt;/p&gt;
  
         &lt;p class=&quot;inline&quot;&gt;
           &lt;%= student_form.label :height %&gt;
           &lt;%= student_form.text_field :height %&gt;
         &lt;/p&gt;
  
         &lt;p class=&quot;inline&quot;&gt;
           &lt;%= student_form.label :weight %&gt;
           &lt;%= student_form.text_field :weight %&gt;
         &lt;/p&gt;
  
         ///// removed for brevity /////
        
      &lt;% end %&gt;
  
      &lt;%= f.fields_for :parents do |parent_form| %&gt;
        &lt;%= render 'parents', :f =&gt; parent_form %&gt;
      &lt;% end %&gt;
  </code></pre>
  <p><strong>Parent Partial</strong></p>
  <pre><code>&lt;p&gt;
    &lt;%= f.label :name, 'Name' %&gt;
    &lt;%= f.text_field :name %&gt;
  &lt;/p&gt;
  
  //// and more of the same /////
  </code></pre>
  <p><strong>Routes</strong></p>
  <pre><code>resources :interviews do
    resources :student
    resources :parents
  end
  </code></pre>
  <p>The website form (at it's current state) can be found here: <a href="http://www.compassconsultingwi.com/interviews/new" rel="nofollow noreferrer">www.compassconsultingwi.com/interviews/new</a></p>
  <p>and the link to the github can be found here: <a href="https://github.com/plantoteachme/compassconsultingwi" rel="nofollow noreferrer">https://github.com/plantoteachme/compassconsultingwi</a></p>
  <p><strong>Params</strong> returns this ..</p>
  <pre><code>Parameters: {&quot;utf8&quot;=&gt;&quot;✓&quot;, &quot;authenticity_token&quot;=&gt;&quot;nU4WM2RO5GJd36eaSLHMxhRQCOnY8EPjDhUdFBHlYGkcw6H7/Oc5y7kFx0HMU9nm5cc47ZZZBDW6oQ2QNF5yhA==&quot;, &quot;interview&quot;=&gt;{&quot;date_today(2i)&quot;=&gt;&quot;11&quot;, &quot;date_today(3i)&quot;=&gt;&quot;16&quot;, &quot;date_today(1i)&quot;=&gt;&quot;2016&quot;, &quot;date_contact(2i)&quot;=&gt;&quot;10&quot;, &quot;date_contact(3i)&quot;=&gt;&quot;23&quot;, &quot;date_contact(1i)&quot;=&gt;&quot;2016&quot;, &quot;student&quot;=&gt;{&quot;name&quot;=&gt;&quot;John&quot;, &quot;age&quot;=&gt;&quot;12&quot;, &quot;height&quot;=&gt;&quot;5 feet&quot;, &quot;weight&quot;=&gt;&quot;123 lbs&quot;, &quot;dob(2i)&quot;=&gt;&quot;3&quot;, &quot;dob(3i)&quot;=&gt;&quot;13&quot;, &quot;dob(1i)&quot;=&gt;&quot;2004&quot;, &quot;strengths&quot;=&gt;&quot;Great with his siblings&quot;, &quot;weaknesses&quot;=&gt;&quot;Lazy&quot;, &quot;likes&quot;=&gt;&quot;Food&quot;, &quot;dislikes&quot;=&gt;&quot;Chores&quot;, &quot;medical_prolems&quot;=&gt;&quot;ADD&quot;, &quot;religous_training&quot;=&gt;&quot;Catholic&quot;, &quot;ethnic_issues&quot;=&gt;&quot;none&quot;, &quot;grade_level&quot;=&gt;&quot;6&quot;}, &quot;parents&quot;=&gt;{&quot;name&quot;=&gt;&quot;Jamie&quot;, &quot;relationship&quot;=&gt;&quot;Mom&quot;, &quot;parentage&quot;=&gt;&quot;Strict&quot;, &quot;address&quot;=&gt;&quot;Miwaukee Wi&quot;, &quot;phone_home&quot;=&gt;&quot;555-1000&quot;, &quot;phone_work&quot;=&gt;&quot;555-1001&quot;, &quot;phone_mobile&quot;=&gt;&quot;555-1002&quot;, &quot;email&quot;=&gt;&quot;jj@jj.com&quot;, &quot;employer&quot;=&gt;&quot;Googleer&quot;, &quot;notes&quot;=&gt;&quot;PhD in Computer Science&quot;}, &quot;purpose_of_call&quot;=&gt;&quot;Depression causing suicidal tendencies&quot;, &quot;problems_start_date&quot;=&gt;&quot;When we moved from Nigeria last year&quot;, &quot;cause&quot;=&gt;&quot;Relocating&quot;, &quot;violence&quot;=&gt;&quot;none&quot;, &quot;running_away&quot;=&gt;&quot;no&quot;, &quot;police_contact&quot;=&gt;&quot;no&quot;, &quot;suicide&quot;=&gt;&quot;Hasn't acted on it, but talks about it&quot;, &quot;self_harm&quot;=&gt;&quot;Minor bruising from \&quot;sports\&quot;&quot;, &quot;other_info&quot;=&gt;&quot;&quot;, &quot;testing&quot;=&gt;&quot;Yes, for ADD&quot;, &quot;hospitalization&quot;=&gt;&quot;no&quot;, &quot;medications&quot;=&gt;&quot;Regeline&quot;, &quot;school_problems&quot;=&gt;&quot;Getting bullied&quot;, &quot;teacher_relationships&quot;=&gt;&quot;Strained&quot;, &quot;parent_goals&quot;=&gt;&quot;Improve self awareness&quot;, &quot;notes&quot;=&gt;&quot;Our family was in Nigeria for mission work&quot;}, &quot;button&quot;=&gt;&quot;&quot;}
  </code></pre>
  <p>Unpermitted parameters: student, parents</p>