I would like to be able to check if any of my object's attributes are nil when updating them so that I can display them to my users as a "draft" or "complete." Is there a way to check this? Or is there a better way of implementing functionality for this?
I have a bool attribute in the table called :complete. I'd like to change this to true or false, depending on it's state. Or, is there a way to check all attributes in the view for a nil attribute, and then remove the :complete attribute?
To check if any of the object's attributes are nil
, you can do
@object.attributes.values.include?(nil)
or
@object.attributes.values.any? &:nil?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments