我修改了一个模型,使其包含一个新字段,例如...
field :url, :type => String
我使用activeadmin,所以当我创建一个新条目时,@model.url是空的,而在更改模式之前创建的条目中,它是nil。如何同时选择两个?我试过了:
# Returns nils and strings
Model.where(:url.ne => "").count 
# Returns strings and ""
Model.where(:url.ne => nil).count
# Returns strings, nils and ""
Model.where(:url.ne => ["", nil]).count 或者,如果有针对这种情况的最佳实践,请告诉我。
发布于 2012-04-27 02:36:35
试一试
Model.where(:url.ne => "", :url.exists => true).count请参阅Mongoid Symbol Operators
https://stackoverflow.com/questions/10337847
复制相似问题