title: Rails 4: has_one - belongs_to: nested model instance attributes won't assign
body: <p>I am having this weird issue where instance[:attribute] works on assignment and writing the attribute but instance.attribute, instance.update, etc. , all fails to change the value of the attribute in the model instance. </p>
  
  <p>Here is a user model:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_one :api_account, inverse_of: :user, dependent: :destroy
  
  # Other user-specific validations come after
  </code></pre>
  
  <p>Here is the associated api_account:</p>
  
  <pre><code>class ApiAccount &lt; ACtiveRecord::Base
    belongs_to :user, inverse_of: :api_account
    validates :access_token, presence: true
    validates :user, presence: true,
                     uniqueness: true
  </code></pre>
  
  <p>In the api_account controller, I have:</p>
  
  <pre><code>response = ### Some JSON response from a distant server
  
  @api_account = @user.create_api_account(:access_token =&gt; response[:access_token])
  # -&gt; This doesn't work and does not set the access_token attribute in the database.
  # id: 2, access_token: nil, user_id: nil, created...
  </code></pre>
  
  <p>Then I changed that to <code>@api_account = @user.build_api_account(:access_token =&gt; response[:access_token])</code> and then <code>user_id: 1</code> but <code>access_token: nil</code>.</p>
  
  <p>In the rails console: <code>@a = @u.build_api_account</code> works and <code>@a[:access_token] = "access_token"</code> works and save persists that change. But everything else I tried fails.</p>
  
  <p>NOTE: <code>@a.access_token = "access_token"</code>, changes the attribute for just <code>@a.access_token</code>; but an inspection of @a still shows that the "access_token attribute is <code>nil</code>. </p>
  
  <p>The schema for the api_account looks like this:</p>
  
  <pre><code>create_table "api_accounts", force: true do |t|
    t.text     "access_token"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "user_id"
  end
  
  add_index "api_account", ["user_id"], name: "index_api_accounts_on_user_id"
  </code></pre>
  
  <p>Does anybody know what is going wrong here? User instances work fine - normal attribute manipulation works great. I am totally lost. There is something different with "has_one" and not as much documentation out there as "has_many".</p>