Reputation: 147
I have a string in code:
@card = Card.offset(rand(Card.count)).where("review_date"<=Time.now).first
I need 1 random record with date equal or less current date. but it show the error invalid date
Upvotes: 0
Views: 35
Reputation: 3268
try this
@card = Card.where("review_date <= ?" , Time.now).limit(1).offset(rand(Card.count))
but here there is an extra overhead of count query first which will run as
Card.count
which you are using for offset.
Upvotes: 1