0
我期待发布出席率小于或等于(< =)当前记录的所有记录,但我很挣扎。查找出席记录的人的问题.where <=当前记录
我的模型是...
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_attend = @student.attendance.sum(:attend) %>
<% @student.attendance.where(:student_id=> :id).where("attend <= ?", student_attend).each do |att| %>
<%= att.name %>
...但不工作,也没有其他派生我已经尝试过。
有人会友好地指点我在正确的方向吗?
预先感谢您!
工作完美,谢谢! – thegreengiant 2014-10-07 10:33:19