2

我有以下型号

class User    
has_many :projects, :through => :bids
has_many :bids, :dependent => :destroy
end

class Project
attr_accessible :name, :user_id

has_many :users, :through => :bids
has_many :bids, :dependent => :destroy

belongs_to :projectmanager, :class_name => "User", :foreign_key => "user_id"

end

class Bid
attr_accessible :project_id, user_id
belongs_to :user
belongs_to :project
end

如您所见,我的Project类同时具有 *has_many* 和 *belongs_to* 到同一个模型(User

项目控制器我有

def new
@project = Project.new
@project.gencontr = current_user

其中current_user是设计当前登录用户。

当我保存项目时,Projects表中的user_id列始终为空。你能告诉我这个我哪里出错了......谢谢

4

1 回答 1

1

关于创建动作

def create
  @project = Project.new(prams[:project])
  @project.projectmanager = current_user
  .......
end 
于 2013-05-21T06:58:46.330 回答