Question

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?

Was it helpful?

Solution

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?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top