我试图显示预订的@ratings,只要它的“结束”字段小于Time.now。
这有效(但没有时间限制):
@ratings = Rating.where(user_id: current_user.id).includes(:reservation).includes(:room)
我正在尝试使用“reservations.end< Time.now”限制查询,如下所示:
@ratings = Rating.where(user_id: current_user.id, reservations.end < Time.now).includes(:reservation).includes(:room)
但它不起作用。
答案 0 :(得分:2)
@ratings = Rating.includes(:reservation, :room).where(user_id: current_user.id).where("reservations.end < ?", Time.now)