title: Rails Active Record: Calling Build Method Should Not Save To Database Before Calling Save Method
body: <p>I have a simple user model</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      has_one :user_profile
  end
  </code></pre>
  
  <p>And a simple user_profile model</p>
  
  <pre><code>class UserProfile &lt; ActiveRecord::Base
      belongs_to :user
  end
  </code></pre>
  
  <p>The issue is when I call the following build method, without calling the save method, I end up with a new record in the database (if it passes validation)</p>
  
  <pre><code>class UserProfilesController &lt; ApplicationController
  
  def create
          @current_user = login_from_session
          @user_profile = current_user.build_user_profile(params[:user_profile])
         #@user_profile.save (even with this line commented out, it still save a new  db record)
          redirect_to new_user_profile_path
  
  end
  </code></pre>
  
  <p>Anyyyyyy one have anyyy idea what's going on.  </p>
  
  <p>The definition of this method says the following but it's still saving for me</p>
  
  <pre><code>build_association(attributes = {})
  
      Returns a new object of the associated type that has been instantiated with attributes and linked to this object through a foreign key, but has not yet been saved.
  </code></pre>
  
  <p><a href="http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_one" rel="nofollow">http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_one</a></p>