0
我試圖在我的活動記錄數據庫上加入兩個不同的條件。 通常我會用逗號(,
)或AND
加入它們,但在這種情況下,在條件之間放置逗號或AND會返回錯誤。使用Where方法在Rails ActiveRecord中加入多個條件
不知如何加入這些條件集中在一個聲明:
MyTable.where("created_at < ?", Time.now - 86400) # 86400 represent a day
MyTable.where(my_column: my_variable)
感謝。
UPDATE
我使用的鐵軌4
謝謝!好的解決方案 –
還有'MyTable.where(...)。where(...)'如果分離條件更容易閱讀。 –