0
所以这一个难倒了我。我有以下基本模型结构;Rails:将current_id值与平均值(3个表)进行比较
class Student < ActiveRecord::Base
has_many :attendances
has_many :classes, :through => :attendances
end
class Attendance < ActiveRecord::Base
belongs_to :student
validates :student_id, presence: true
belongs_to :class
validates :class_id, presence: true
end
class Class < ActiveRecord::Base
has_many :attendances
has_many :students, :through => :attendances
end
我想建立一个简单的应用程序,对学生(谁是当前登录的用户),我们将展示他们的平均上座率给定类,再加上平均上座率为该类所有学生。
考勤记录只是主持student_id,class_id和考勤(当前是一个整数)。
所以一个真实的例子是;
学生出勤率在生物 - 生物学80 平均学生出勤率 - 96
我已经试过
我试图在学生控制器的显示方面来定义@students = Student.all
,并要求考勤和班级参数,并在我看来运行@students.attendance.average('attended')
- {其中'出席'是持有整数的列'} - 但我得到一个错误,'出席'是未定义的。
我在哪里错了?
感谢所有