Method: Binda::FieldableAssociationHelpers::FieldableImageHelpers#has_image

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

#has_image(field_slug) ⇒ boolean

Check if the field has an attached image

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (boolean)

Raises:

  • (ArgumentError)


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

def has_image(field_slug)
	obj = self.images.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
	# Alternative query
	# obj = Image.where(field_setting_id: FieldSetting.get_id( field_slug ), fieldable_id: self.id, fieldable_type: self.class.to_s ).first
	raise ArgumentError, "There isn't any image associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	return obj.image.present?
end