2014-12-05 115 views
0

我想重用我定义的范围,但它返回一个数组。Rails 4链接范围

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>' 

回答

1

Rails不具有或声明。你可以直接编写SQL,虽然这样的东西就像

where("(started_at < NOW() or started_at = null) and ended_at > NOW() and published_at < NOW()")