2015-09-16 33 views
0

我是ROR編程的初學者,我試着用下面的代碼來做選擇計劃。當我在計算機上執行操作時,我得到了正確的輸出結果,但在heroku中部署後出現錯誤。 這裏datesheduleSchedule表的列。如何選擇本月的記錄,在rails中使用Active Record Query Interface

def index 
if 
@schedules=Schedule.where("strftime('%m', dateshedule) = ?", Date.today.strftime('%m')) 

    else 

    @schedules = Schedule.all 
    end 

這是在views /時間表/ index.html.erb Schedule for this month

回答

2

的代碼,您將無法在where子句中使用strftime的,因爲它是一個紅寶石功能,底層數據庫不知道。這將工作更好(假設列和表的拼寫是正確的;它似乎不一致在您的文章)

@schedules = Schedule.where('dateschedule >= ? AND dateschedule <= ?', DateTime.now.beginning_of_month, DateTime.now.end_of_month) 
+0

非常感謝,它的工作 –

相關問題