0

I have a rails model object where i am checking for presence of whether some select attribute values are present or not.

For example lets say person model has fname, lname, age attributes.How can i check for the presence of fname, lname alone not being blank or null, For instance i know that we can do something like person.fname.present? && person.lname.present? but is there a more concise and ruby-friendly way to do the same?

  • Looks fine. See this answer for some additional details: https://stackoverflow.com/a/39212101/11509906 – Sumak Aug 31 '21 at 09:02

1 Answers1

0

You can add any attribute you want to check as argument of values_at function.

person.attributes.values_at(:fname, :lname).all?(&:present?)
Dharman
  • 30,962
  • 25
  • 85
  • 135