I created model Profile.rb
I have on the db column name
, Currently it's empty
How do I check on the rails console if Profile is empty?
I have tried Profile.empty?
but I guess that's not the right way
Specifically, if the object responds to #empty? , they will check whether it is empty. If you go to http://api.rubyonrails.org/ and search for "blank?", you will see what objects it is defined on and how it works.
nil? will only return true if the object itself is nil. That means that an empty string is NOT nil and an empty array is NOT nil.
Let's start out with “Nil” since it's the most common and easy-to-understand way of representing nothingness in Ruby. In terms of what it means, Nil is exactly the same thing as null in other languages. So, what is null? Null, as it exists in many languages, is a sort of value that represents “nothing”.
This also could be an Option for you.
Profile.any?
This will make a query to DB like
Profile.any?
# (0.6ms) SELECT COUNT(*) FROM "profiles"
# => false
This would be more semantic I guess.
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