我创建了多个Teacher
和Sclass
的关联。 ClassTeacher
是联接表名称。
class Teacher < ActiveRecord::Base
has_many :class_teachers
has_many :Sclasses, :through => :class_teachers
attr_accessible :teacher_id
attr_accessible :tname
attr_accessible :mob
attr_accessible :email
end
class Sclass < ActiveRecord::Base
set_primary_key :year
has_many :class_teachers
has_many :teachers, :through => :class_teachers
attr_accessible :year
end
class ClassTeacher < ActiveRecord::Base
belongs_to :teacher
belongs_to :sclass
attr_accessible :year
attr_accessible :teacher_id
end
我在视图中有tlist.html.erb
,tnew.html.erb
- &gt;教师文件夹,同样我在视图中有slist.html.erb
,snew.html.erb
- &gt; sclasses文件夹。
当我为Teacher
添加记录时,它也应该要求years
并保存记录。同样,对于一年,它应该要求teacher_ids
并保存记录。我怎么能这样做?这些记录将保存在哪里?