1
我在哪裏錯了?我得到這個錯誤:ActiveRecord未知屬性錯誤(Sinatra)
unknown attribute: bar_id
我有以下兩類:
class Foo < ActiveRecord::Base
belongs_to :bar
end
class Bar < ActiveRecord::Base
has_many :bazs
has_many :foos
end
,當我嘗試創建新FOOS使用我得到這個錯誤:
@bar = Bar.find(1)
@bar.foos.create(:attribute1 => "a",
:attribute2 => "b")
是的,我的意思是新的Foos。我已經適當更新了這個問題。我認爲在正確的位置擁有'belongs_to'和'has_many'會在我的'foos'表中爲我處理'bar_id'。我添加了'bar_id',它工作正常!感謝Leo。 – sway 2013-04-08 00:20:30