Method: Binda::FieldableAssociationHelpers::FieldableDateHelpers#has_date

Defined in:
app/models/concerns/binda/fieldable_association_helpers/fieldable_date_helpers.rb

#has_date(field_slug) ⇒ datetime, boolean

Check if the field has an attached date

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (datetime)

    The date

  • (boolean)

    Reutrn false if nothing is found

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_date_helpers.rb', line 9

def has_date(field_slug)
	obj = self.dates.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	raise ArgumentError, "There isn't any date associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	if obj.present?
		return !obj.date.nil?
	else
		return false
	end
end