title: Rails unpermitted parameter when nesting forms multiple levels deep
body: <p>I have 3 models, a <code>Property</code> has_many <code>units</code> and each unit belongs to a Property. A <code>Unit</code>  has_one <code>unit_amenity</code> and a <code>unit_amenity</code> belongs to a unit.  The issue is that I need to nest the unit_amenity form which is 2 levels down in the new property form and I'm getting an <code>Unpermitted parameter</code> error.  I also see just &quot;unit_amenity&quot;=&gt;{&quot;heat&quot;=&gt;&quot;1&quot;} in the logs instead of &quot;unit_amenity_attributes&quot;=&gt;{&quot;heat&quot;=&gt;&quot;1&quot;}.</p>
  <p>Property.rb</p>
  <pre><code>class Property &lt; ApplicationRecord  
    has_many :units, dependent: :destroy
    accepts_nested_attributes_for :units, allow_destroy: true 
  end
  </code></pre>
  <p>Unit.rb</p>
  <pre><code>class Unit &lt; ApplicationRecord
    belongs_to :property
  
    has_one :unit_amenity, dependent: :destroy
    accepts_nested_attributes_for :unit_amenity, allow_destroy: true 
  end
  </code></pre>
  <p>Unit_amenity.rb</p>
  <pre><code>class UnitAmenity &lt; ApplicationRecord
    belongs_to :unit
  end
  </code></pre>
  <p>I have nested the unit_amenity params within the unit params in properties_controller.rb</p>
  <pre><code>    # Only allow a list of trusted parameters through.
      def property_params
        params.require(:property).permit(:city, :state, :zip_code, 
          units_attributes: [ :id, :_destroy, :unit_number, :bedrooms, :bathrooms, :property_id,
            unit_amenity_attributes: [ :id, :_destroy, :unit_id, :heat, :air_conditioning ] ])
        end
      end
  </code></pre>
  <p>The form has a nested fields_for for unit_amenity</p>
  <pre><code>    &lt;%= form_with(model: property) do |form| %&gt;
          &lt;div class=&quot;col-span-6&quot;&gt;
            &lt;%= form.label :city %&gt;
            &lt;%= form.text_field :city %&gt;  
          &lt;/div&gt;
          ....
  
          &lt;%= form.fields_for :unit_amenity do |amenity_field| %&gt;
            &lt;div&gt;
              &lt;%= amenity_field.check_box :heat, class: '', type: 'checkbox', id: 'heat' %&gt;
              &lt;%= amenity_field.label :heat, class: &quot;text-sm font-medium text-gray-700&quot; %&gt;                   
            &lt;/div&gt;                
             ....
         &lt;% end %&gt; 
      &lt;% end %&gt; 
  </code></pre>
  <p>The <code>new</code> action of the properties_conroller.rb</p>
  <pre><code>  def new
      @property = Property.new
      
      units = @property.units.build # has_many association
      units.build_unit_amenity # has_one association
    end
  </code></pre>