Method: Binda::FieldableAssociationHelpers::FieldableTextHelpers#has_text

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

#has_text(field_slug) ⇒ boolean

Get the object related to that field setting

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (boolean)

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_text_helpers.rb', line 42

def has_text(field_slug)
	obj = Text
		.includes(:field_setting)
		.where(fieldable_id: self.id, fieldable_type: self.class.name)
		.where(binda_field_settings: { slug: field_slug })
		.where.not(binda_field_settings: { field_type: "string" })
		.first
	raise ArgumentError, "There isn't any text associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil?
	if obj.present?
		return !obj.content.nil?
	else
		return false
	end
end