0

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?

1 Answer 1

2

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?
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.