遇到一些挑战时,需要跟踪员工所学的课程。这就是到目前为止我手头上的表格
Course: course_id,name,category_of_course...#holds Course related details
Employee: employee_id, name...#holds Employee details
progress:course_id,employee_id, status ...#holds which course have been
taken and by whom在我的模型中,我有这样的关系:
Employee: has_many :courses请告诉我如何在“选择”列表中填写员工尚未学习的课程(假设在注册课程后,该课程被标记为已学习)。我正在使用带有MySql的rails 3.0.9。谢谢
发布于 2012-02-26 04:19:44
你需要定义
belongs_to :employee
belongs_to :course(在您的进度模型中)
然后,您可以定义
#Employee
has_many :progresses
has_many :courses, :through => :progresses
#Course
has_many :progresses
has_many :employees, :through => :progresses选择列表将为:
= form_for @something do |f|
= f.select :course_id, Course.all.select{|x| not @employee.courses.include?(x)}.collect{|x|[x.name,x.id]} #Ideally this logic should reside in the model.https://stackoverflow.com/questions/9447568
复制相似问题