我有三個模型建立與以下關聯.build方法連接表中沒有創造協會
class User < ActiveRecord::Base
has_many :faculties
has_many :schools, :through => :faculties
end
class School < ActiveRecord::Base
has_many :faculties
has_many :users, :through => :faculties
end
class Faculty < ActiveRecord::Base
belongs_to :user
belongs_to :school
end
,並在我的控制,我去創建一所學校和用戶分配
class SchoolsController < ApplicationController
def create
@school = current_user.schools.build(params[:school])
...
end
end
當我登錄並提交表單時,Flash會顯示成功,但該關聯不會建立在聯接表上。
我在應用程序控制臺裏面試過了,它建立了關聯就好了。
我一直堅持這一兩天了,我只是不知道我失蹤了。預先感謝任何和所有建議
你可以顯示你的current_user方法嗎? – Msencenb 2012-01-14 08:14:10
我正在使用devise – 2012-01-14 08:18:56
您能否顯示創建操作發生時會發生什麼的日誌? – Msencenb 2012-01-14 08:45:39