Method: Binda::FieldableAssociationHelpers::FieldableStringHelpers#get_string

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

#get_string(field_slug) ⇒ string, error

Get the object related to that field setting If the object doesn’t exists yet it will return nil

Parameters:

  • field_slug (string)

    The slug of the field setting

Returns:

  • (string)

    Returns the content of the string

  • (error)

    Raise an error if no record is found



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_string_helpers.rb', line 11

def get_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
	unless obj.nil?
		# to_s ensures the returned object is class String
		obj.content.to_s
	else
		check_string_error field_slug
	end
end