0

定義したスコープを再利用したいのですが、配列が返されます。

scope :currents, -> { (where('started_at < NOW()') | where('started_at' => nil)) & where('ended_at > NOW()') & where('published_at < NOW()') }

def self.findNextAuctions()
  currents.order(ended_at: :asc).limit(3)
end

関数 findNextAuctions を呼び出すと、次のエラーが発生します。

  1) Error:
AuctionTest#test_should_fint_next_auctions:
NoMethodError: undefined method `order' for #<Array:0x007fae5d6e3878>
    app/models/auction.rb:13:in `findNextAuctions'
    test/models/auction_test.rb:14:in `block in <class:AuctionTest>'
4

1 に答える 1

1

Rails には OR ステートメントがありません。ただし、SQLを直接書くことができるので、次のようなものです

where("(started_at < NOW() or started_at = null) and ended_at > NOW() and published_at < NOW()")
于 2014-12-05T22:10:14.537 に答える