访问多对多

时间:2012-08-10 09:16:27

标签: ruby-on-rails ruby-on-rails-3.2

我创建了多个TeacherSclass的关联。 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.erbtnew.html.erb - &gt;教师文件夹,同样我在视图中有slist.html.erbsnew.html.erb - &gt; sclasses文件夹。

当我为Teacher添加记录时,它也应该要求years并保存记录。同样,对于一年,它应该要求teacher_ids并保存记录。我怎么能这样做?这些记录将保存在哪里?

0 个答案:

没有答案