1

I had to create a scope to create active jobs, but this feels a little odd and honestly it's tightly coupled to PosgresSQL:

  scope :active, -> { where('reviewed_at NOTNULL and paid_at NOTNULL and end_at >= ?', Date.today) }

Would you write this differently? Thank you

Chris Hough
  • 3,389
  • 3
  • 41
  • 80

2 Answers2

2

A shorter & more beautiful version will be like this:

scope :active, -> { where.not(reviewed_at: nil, paid_at: nil).where('end_at >= ?', Date.today) }
Hieu Pham
  • 6,577
  • 2
  • 30
  • 50
0

you can use where.not in rails 4

scope :active, -> { where.not(reviewed_at: nil).where.not(paid_at: nil).where('end_at >= ?', Date.today) }
fengd
  • 7,551
  • 3
  • 41
  • 44