2015-04-20 33 views
0

問題我正在使用has_scope gem並試圖找到包含nil/not nil info的列。它不工作。我遇到了has_scope gem

我在我的模型中的兩個範圍:

scope :empty -> where(name: nil) 
scope :present -> where.not(title: nil) 
在我的控制器

has_scope :empty 
    has_scope :present 

    def index 
     clients = apply_scopes(Clients).all 
    end 

在命令行:

捲曲-X GET http://localhost:3000/clients?empty

回答

0

忘記寶石,並直接使用示波器(如自然意圖!)

empty_name_clients = Client.empty 

clients_with_names = Client.present 

另外,我不建議你使用「本」或「空」字的範圍的名稱作爲那些字是由ActiveRecord的和Ruby的集合保留如

Client.last.appointements.empty?Client.last.present?