我正在使用Ruby on Rails 5和Searchkick gem。
我现在在我的控制器中使用它,它工作正常:
@blogs = Blog.search(query, where:{published_at: nil})
但我想使用一个非零的范围,所以:
scope :published, ->{ where.not(published_at: nil )}
但我不知道如何让它在我的控制器中工作,我试过这个,但它不起作用
@blogs = Blog.search(query, where.not:{published_at: nil})
如何获得那些不是零的记录?
这应该适合你:
@blogs = Blog.search(query, where: { published_at: { not: nil } })