Method: Binda::FieldableAssociationHelpers::FieldableAudioHelpers#has_audio
- Defined in:
- app/models/concerns/binda/fieldable_association_helpers/fieldable_audio_helpers.rb
#has_audio(field_slug) ⇒ boolean
Check if the field has an attached audio
8 9 10 11 12 13 14 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_audio_helpers.rb', line 8 def has_audio(field_slug) obj = self.audios.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 audio associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil? return obj.audio.present? end |