It is my expectation that when I create a BrickItem, it will have a reference to a Ability. Yet, when the BrickItem is created, abilities_id is null. Why?
My table create:
create_table "brick_items", :force => true do |t|
t.integer "abilities_id"
My Ability migration:
Ability.create :name => 'my choice'
My controller:
def create
@brick_item = BrickItem.new(params[:brick_item])
@brick_item.build_ability(:id => 1)
My model:
class BrickItem < ActiveRecord::Base
has_one :ability
end
I’m not sure I fully understand the whole picture, but from the code you’ve shared, it appears there are several problems: