title: Unable to implement has_one relationship
body: <p>I am trying to create an account management system that allows an account to have one billing address.  I want the account and address to have their own controller and model. An admin user would create a new account then be redirected to create a new billing address for this account.  The first part works, I am able to create the account, but the second only saves the account_id attribute to the addresses table.  Below is my code:  </p>
  
  <p>accounts_controller</p>
  
  <pre><code>class AccountsController &lt; ApplicationController
   def new
     @account = Account.new
   end  
   def create
      @account = Account.new(params[:account])
      @account.build_address
     if @account.save
       flash[:success] = "Customer Account has been successfully created!"
       redirect_to '/newaddress'
     else
       render 'new'
     end
   end
  end
  </code></pre>
  
  <p>addresses_controller</p>
  
  <pre><code>class AddressesController &lt; ApplicationController  
    def new
      @address = Address.new
    end
    def create
      @account = Account.find(params[:account])
      @address = @account.create_address(params[:address])
      redirect_to root_path
    end
  end
  </code></pre>
  
  <p>account_model</p>
  
  <pre><code>class Account &lt; ActiveRecord::Base
    has_one :address
    accepts_nested_attributes_for :address
    attr_accessible :contactFirstName, :contactLastName, :contactEmail, :contactPhone, :business_name
  end
  </code></pre>
  
  <p>address_model</p>
  
  <pre><code>class Address &lt; ActiveRecord::Base
    attr_accessible :city, :state, :street, :zipCode   
    belongs_to :account
  end
  </code></pre>
  
  <p>I also added the following to my routes.rb file</p>
  
  <pre><code>resources :accounts do
    resources :addresses
  end
  </code></pre>
  
  <p>Last, below is the schema for the relavant tables</p>
  
  <pre><code>create_table "accounts", :force =&gt; true do |t|
    t.string   "contactEmail"
    t.string   "contactFirstName"
    t.string   "contactLastName"
    t.string   "contactPhone"
    t.datetime "joinDate"
    t.string   "business_name"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  create_table "addresses", :force =&gt; true do |t|
    t.string   "city"
    t.string   "state"
    t.string   "street"
    t.string   "zipCode"
    t.integer  "account_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  </code></pre>
  
  <p>(I am still new to programming and rails so I posted as much as I thought would be relevant.)</p>
  
  <p>Added Log from when I open the new account page and then proceed to the new address page.</p>
  
  <pre><code>Started GET "/newaccount" for 127.0.0.1 at Tue Sep 20 17:21:56 -0500 2011
    Processing by AccountsController#new as HTML
  Rendered shared/_error_messages.html.erb (0.6ms)
  Rendered accounts/_account_fields.html.erb (13.0ms)
  Rendered layouts/_stylesheets.html.erb (1.2ms)
    User Load (2.5ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
    CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
  Rendered layouts/_header.html.erb (19.4ms)
  Rendered layouts/_footer.html.erb (1.0ms)
  Rendered accounts/new.html.erb within layouts/application (50.3ms)
  Completed 200 OK in 168ms (Views: 64.6ms | ActiveRecord: 2.5ms)
  
  Started POST "/accounts" for 127.0.0.1 at Tue Sep 20 17:22:11 -0500 2011
    Processing by AccountsController#create as HTML
    Parameters: {"commit"=&gt;"Next", "account"=&gt;{"business_name"=&gt;"FooBar", "contactLastName"=&gt;"Bar", "contactPhone"=&gt;"1231231234", "contactEmail"=&gt;"foo@bar.com", "contactFirstName"=&gt;"Foo"}, "authenticity_token"=&gt;"lJG89TIjcJighmFUWLg1uR9sJq0CHLvceeLH9QNocGY=", "utf8"=&gt;"✓"}
    SQL (0.1ms)  BEGIN
    SQL (0.3ms)  SELECT 1 FROM `accounts` WHERE (LOWER(`accounts`.`contactEmail`) = LOWER('foo@bar.com')) LIMIT 1
    SQL (1.2ms)  describe `accounts`
    AREL (0.4ms)  INSERT INTO `accounts` (`created_at`, `contactFirstName`, `business_name`, `contactPhone`, `updated_at`, `contactEmail`, `contactLastName`, `joinDate`) VALUES ('2011-09-20 22:22:11', 'Foo', 'FooBar', '1231231234', '2011-09-20 22:22:11', 'foo@bar.com', 'Bar', NULL)
    SQL (1.5ms)  describe `addresses`
    AREL (0.2ms)  INSERT INTO `addresses` (`zipCode`, `state`, `city`, `updated_at`, `account_id`, `street`, `created_at`) VALUES (NULL, NULL, NULL, '2011-09-20 22:22:11', 31, NULL, '2011-09-20 22:22:11')
    SQL (26.3ms)  COMMIT
  Redirected to http://localhost:3500/newaddress
  Completed 302 Found in 85ms
  
  Started GET "/newaddress" for 127.0.0.1 at Tue Sep 20 17:22:11 -0500 2011
    Processing by AddressesController#new as HTML
  Rendered addresses/_address_fields.html.erb (83.4ms)
  Rendered layouts/_stylesheets.html.erb (1.4ms)
    User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
    CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
  Rendered layouts/_header.html.erb (17.1ms)
  Rendered layouts/_footer.html.erb (0.9ms)
  Rendered addresses/new.html.erb within layouts/application (113.6ms)
  Completed 200 OK in 126ms (Views: 119.6ms | ActiveRecord: 30.3ms)
  
  Started POST "/newaddress" for 127.0.0.1 at Tue Sep 20 17:22:29 -0500 2011
    Processing by AddressesController#new as HTML
    Parameters: {"address"=&gt;{"city"=&gt;"Boston", "street"=&gt;"123 Main St", "zipCode"=&gt;"02222", "state"=&gt;"MA"}, "commit"=&gt;"Create", "authenticity_token"=&gt;"lJG89TIjcJighmFUWLg1uR9sJq0CHLvceeLH9QNocGY=", "utf8"=&gt;"✓"}
  Rendered addresses/_address_fields.html.erb (10.3ms)
  Rendered layouts/_stylesheets.html.erb (1.2ms)
    User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
    CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
  Rendered layouts/_header.html.erb (17.2ms)
  Rendered layouts/_footer.html.erb (0.9ms)
  Rendered addresses/new.html.erb within layouts/application (40.1ms)
  Completed 200 OK in 54ms (Views: 47.3ms | ActiveRecord: 0.2ms)
  </code></pre>