Rails methods - returning boolean values
suggest changeA model method can return a boolean. A relation does not.
This returns an ActiveRecord::Relation. The relation object is always truthy, even when no row matches. !! does not turn it into “any records existed”. The table is users, not user, and self is not an id.
def matching_profile
User.includes(:profile_pictures, :address, :contact_detail).where(id: id)
end
Ask the database if a row exists:
def profile_complete?
User.where(id: id).exists?
end
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents