attribute_present?

attribute_present?(attribute)
Instance Public methods

Returns true if the specified attribute has been set by the user or by a database load and is neither nil nor empty? (the latter only applies to objects that respond to empty?, most notably Strings). Otherwise, false. Note that it always returns true with boolean attributes.

class Task < ActiveRecord::Base
end

person = Task.new(title: '', is_done: false)
person.attribute_present?(:title)   # => false
person.attribute_present?(:is_done) # => true
person.name = 'Francesco'
person.is_done = true
person.attribute_present?(:title)   # => true
person.attribute_present?(:is_done) # => true
doc_ruby_on_rails
2015-06-20 00:00:00
Comments
Leave a Comment

Please login to continue.