Today I Learned

hashrocket A Hashrocket project

The versatility of the `exists?` method

My normal use of the exists? method in ActiveRecord has always been to toss it on the end of a query of some kind:

Animal.where(name: "dragon").exists?
# => false

However, I discovered that the method can be called directly on a class and passed options:

Animal.exists?(name: "dragon")
Animal.exists?(123)
Animal.exists?(id: [123, 345])

Check out the full documentation for more examples

See More #rails TILs
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.