I have a user model with optional twitter integration.
I've added a 'username' attribute that is only filled when a user has completed twitter authentication.
I want to find all users with the integration. What is the best way to find all objects where an attribute is something, or where it is not nil?
Rails4 / Rails 5:
User.where.not(username: nil)
Rails 3:
User.where("username <> nil")
I would love to see other responses
you can also do just write the sql in the where statement:
User.where("username <> nil")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With