title: Can't update my nested model form for has_one association
body: <p>I try to create a nested model form for the has_one association. (i'm using Rails 4)</p>
  
  <p>In my user, and adress model i have the following :</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
   has_one :address
   accepts_nested_attributes_for :address
  end
  
  class Address &lt; ActiveRecord::Base
   belongs_to :user
  
  end
  </code></pre>
  
  <p>my user controller :</p>
  
  <pre><code>class UsersController &lt; ApplicationController
      .
      .
      .
      def edit
        @user = User.find(params[:id]) 
        @user.build_address if @user.address.nil?
      end 
  
      def update
        @user = User.find(params[:id])
        if @user.update(params.require(:user).permit(:user_name, address_attributes: [:street]))
          flash[:success] = "Profile updated successfully"
          sign_in @user
          redirect_to @user
        else
           flash.now[:error] = "Cannot updating your profile"
           render 'edit'
        end
      end
  end
  </code></pre>
  
  <p>finally in my view i have :</p>
  
  <pre><code>= form_for(@user) do |f|
    = render 'shared/error_messages', object: f.object
    %div
      = f.label :user_name, "User name"
      = f.text_field :user_name
      = f.fields_for :address do |add|
        = addd.label :street
        = d.text_field :street
      = f.submit "Update"
  </code></pre>
  
  <p>When i try to fill street filed for the first time it works, but when i try to <strong>update</strong> i get the error : <code>Failed to remove the existing associated address. The record failed to save after its foreign key was set to nil</code></p>
  
  <p>any idea where is the error ? thank's</p>