Method: Binda::FieldableAssociationHelpers::FieldableStringHelpers#has_string

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

#has_string(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)


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_string_helpers.rb', line 40

def has_string(field_slug)
  obj = Text
    .includes(:field_setting)
    .where(fieldable_id: self.id, fieldable_type: self.class.name)
    .where(binda_field_settings: { slug: field_slug, field_type: "string" })
    .first
  raise ArgumentError, "There isn't any string 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