0
我有以下型号嵌套表格不及格belongs_to的:ID
class Project < ActiveRecord::Base
has_many :assignments, :conditions => {:deleted_at => nil}
has_many :members, :conditions => {:deleted_at => nil}
accepts_nested_attributes_for :members, :allow_destroy => true
end
class Member < ActiveRecord::Base
belongs_to :project
belongs_to :person
belongs_to :role
has_many :assignments, :dependent => :destroy, :conditions => {:deleted_at => nil}
accepts_nested_attributes_for :assignments, :allow_destroy => true
validates_presence_of :role_id
validates_presence_of :project_id
end
,我以为控制器将填充在project.save的member.project_id每个嵌套成员记录。但是,我收到验证错误,指出project_id为空。
我控制器的方法:
def create
# @project is created in before_filter
if @project.save
flash[:notice] = "Successfully created project."
redirect_to @project
else
render :action => 'new'
end
end
我是否需要手动设置PROJECT_ID在每个嵌套成员记录?或者当创建成员记录时,控制器需要填充什么?
这是否必要是@project已经被保存到数据库?我正在尝试克隆一个现有的项目,并且一次保存一个新的project_id。 – 2010-05-04 19:48:39