title: Rails 4 has_one association form not building
body: <p>I need some pointers on how Rails 4 works with has_one and belongs_to association.</p>
  
  <p>My form doesn't save the <code>has_one</code> relationship</p>
  
  <p><strong>Post Model</strong></p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    validates: :body, presence: true
  
    has_one :category, dependent: :destroy
    accepts_nested_attributes_for :category
  end
  
  class Category &lt; ActiveRecord::Base
    validates :title, presence: true
    belongs_to :post
  end
  </code></pre>
  
  <p><strong>Post Controller</strong></p>
  
  <pre><code>class PostController &lt; ApplicationController
    def new
      @post = Post.new
      @post.build_category
    end
  
    def create
      @post = Post.new(post_params)
    end
  
    private
  
    def post_params
      params.require(:post).permit(:body)
    end
  end
  </code></pre>
  
  <p><strong>Form in the Post#new action</strong></p>
  
  <pre><code>&lt;%= form_for @post do |form| %&gt;
  
    &lt;%= form.label :body %&gt;
    &lt;%= form.text_area :body %&gt;
  
    &lt;%= fields_for :category do |category_fields| %&gt;
      &lt;%= category_fields.label :title %&gt;
      &lt;%= category_fields.text_field :title %&gt;
    &lt;% end %&gt;
  
    &lt;%= form.button "Add Post" %&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>It's not saving the <code>category</code> title when the Post form is submitted.</p>
  
  <p><strong>Debug params</strong></p>
  
  <pre><code>utf8: ✓
  authenticity_token: 08/I6MsYjNUhzg4W+9SWuvXbSdN7WX2x6l2TmNwRl40=
  post: !ruby/hash:ActionController::Parameters
    body: 'The best ice cream sandwich ever'
  category: !ruby/hash:ActiveSupport::HashWithIndifferentAccess
    title: 'Cold Treats'
  button: ''
  action: create
  controller: posts
  </code></pre>
  
  <p><strong>App log</strong></p>
  
  <pre><code>Processing by BusinessesController#create as HTML
    Parameters: {"utf8"=&gt;"✓",
                 "authenticity_token"=&gt;"08/I6MsYjNUhzg4W+9SWuvXbSdN7WX2x6l2TmNwRl40=",
                 "post"=&gt;{"body"=&gt;"The best ice cream sandwich ever"},
                 "category"=&gt;{"title"=&gt;"Cold Treats", "button"=&gt;""}
  </code></pre>
  
  <p>In the Rails console.. I can run the following succesfully</p>
  
  <pre><code>&gt; a = Post.new
  =&gt; #&lt;Post id: nil, body: ""&gt;
  &gt; a.category
  =&gt; nil
  
  &gt; b = Post.new
  =&gt; #&lt;Post id: nil, body: ""&gt;
  &gt; b.build_category
  =&gt; #&lt;Post id: nil, title: nil&gt;
  &gt; b.body = "The best ice cream sandwich ever"
  =&gt; "The best ice cream sandwich ever"
  &gt; b.category.title = "Cold Treats"
  =&gt; "Cold Treats"
  </code></pre>
  
  <p>The questions I have the relates to how to tackle this problem:</p>
  
  <ol>
  <li>I'm not sure if I have to add <code>:category_attributes</code> in the <code>post_params</code> strong parameter method?</li>
  <li>Should the logs and debug params show that the <code>Category</code> attributes
  are nested inside the <code>Post</code> parameter?</li>
  <li>In the <code>Category</code> hash parameter there is a blank <code>button</code> key that isn't in my <code>fields_for</code> am I missing something when using the form helpers?</li>
  <li>Is the reason because the create action doesn't take the
  <code>build_category</code> method and I will need to add this to the create
  action?</li>
  <li>Will validations on the <code>Category</code> model (<code>presence: true</code>) be
  automatically used on the <code>Post</code> form?</li>
  </ol>
  
  <p>Thanks in advance.</p>
  
  <h1>Update: missing <code>category_fields</code> inside <code>fields_for</code> block.</h1>