2016-04-20 82 views
0

問題:我只想在學生/演出中僅顯示即將到來的參加者(不是過去的)。通過控制器導軌依賴於過濾器的數據

- scaffold lesson name starts_at:datetime ends_at:datetime

- scaffold attendance student:references lesson:references

- scaffold student name

student has_many :attendanceslesson has many :attendancesstudent has_many :lessons, through: :attendances

我試圖

students_controller.rb:

@future_attendances = @student.attendances.where('lesson.starts_at > ?', Time.now)

學生/ show.html.haml:

 %table 
     %thead 
      %tr 
      %th Title 
      %th Starts at 
     %tbody 
      - @future_attendances.each do |attendance| 
      %tr 
       %td= attendance.lesson.name 
       %td= attendance.lesson.starts_at 

但它不起作用。有任何想法嗎?

+0

您是否收到任何錯誤? – Uzbekjon

+0

什麼「不起作用」呢?是否顯示過去的參加人數,路線是否中斷,是否顯示錯誤等 – PhilVarg

+0

'SQLite3 :: SQLException:no such column:lesson.starts_at:SELECT「attendances」。* FROM「attendances」WHERE「attendances」。「student_id」=? AND(lesson.starts_at>'2016-04-20 22:07:13.208768')' –

回答

1

瞎猜,你能不能只是做:

@future_lessons = @student.lessons.where('starts_at > ?', Time.now) 

然後:

%tbody 
    - @future_lessons.each do |lesson| 
    %tr 
     %td= lesson.name 
     %td= lesson.starts_at 

,因爲你正在尋找在課程表中的列您當前的代碼不起作用。您需要使用joins方法將課程表添加到查詢以使其工作。但是,我認爲上面的路線就是你真正想要的。

+0

重要的一點是,它必須是'每個人都必須|出勤|' –

+0

是的,讓我改寫... – GoGoCarl

+0

@YaroAlexShm Doesn這似乎是出席(加入班)是必要的。只要跳到課堂上。 – GoGoCarl