Rails Where multiple values, one is not nil

This code retrieves records where foobar is Nil

Model.where(user_id: 14, foobar: nil) 

How can I use the same syntax and get NOT nil?

Something like:

 Model.where(user_id: 14, foobar: !nil) 
+7
ruby-on-rails activerecord
source share
2 answers
 Model.where(user_id: 14).where("foobar IS NOT NULL") Model.where("user_id = ? AND foobar IS NOT ?", 14, nil) 
+6
source share

Rails 4:

 Model.where(user_id: 14).where().not(foobar: nil) 

Rails 3 - Rails where the condition is NOT NULL

+10
source share

All Articles