title: Rails 4: fields_for in fields_for
body: <p>I am learning RoR and i am trying to find how to set a fields_for in another one with has_one models like this:</p>
  
  <pre><code>class Child &lt; ActiveRecord::Base
      belongs_to :father
      accepts_nested_attributes_for :father
  end
  
  class Father &lt; ActiveRecord::Base
      has_one :child
      belongs_to :grandfather
      accepts_nested_attributes_for :grandfather
  end
  
  
  class Grandfather &lt; ActiveRecord::Base
      has_one :father
  end
  </code></pre>
  
  <p>I used Nested Model Form Part 1 on Railscasts to get these:
  In children_controller.rb:</p>
  
  <pre><code>  def new
      @child = Child.new
      father=@child.build_father
      father.build_grandfather
    end
  
  def child_params
        params.require(:child).permit(:name, father_attributes:[:name], grandfather_attributes:[:name])
      end
  </code></pre>
  
  <p>And my form:</p>
  
  <pre><code>&lt;%= form_for(@child) do |f| %&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :name %&gt;&lt;br&gt;
      &lt;%= f.text_field :name %&gt;
    &lt;/div&gt;
    mother:&lt;br&gt;
    &lt;%= f.fields_for :father do |ff| %&gt;
      &lt;%= ff.label :name %&gt;
      &lt;%= ff.text_field :name %&gt;&lt;br&gt;
        grand mother:&lt;br&gt;
        &lt;%= f.fields_for :grandfather do |fff| %&gt;
          &lt;%= fff.label :name %&gt;
          &lt;%= fff.text_field :name %&gt;
        &lt;% end %&gt;
    &lt;% end %&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I am trying to retrieve the datas with:</p>
  
  <pre><code>&lt;%= child.father.name %&gt;
  &lt;%= child.father.grandfather.name %&gt;
  </code></pre>
  
  <p>but the grandfather's name won't work.
  I cannot find the mistake(s)...anyone to help on this?
  Thanks!</p>