Jigar Patel Driving fast in a slow lane!

Methods We Don't Use - 'attribute_present?'

October 12, 2010 / Jigar Patel

We usually check the value of an attribute by using object.attribute.blank?. This method works fine when the attribute has been defined by the user or it has been loaded by the database. But it will raise a NoMethodError if the attribute is not defined by the user and is not loaded by the database.

We can use attribute_present? method to check both the existence of an attribute and its value. The method takes attribute name as message and returns boolean value.