私は次のモデルを持っています
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 を手動で設定する必要がありますか? または、コントローラーがメンバー レコードを作成するときに入力する必要があるものは何ですか?