Class: Binda::FieldGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Binda::FieldGroup
- Extended by:
- FriendlyId
- Defined in:
- app/models/binda/field_group.rb
Instance Method Summary collapse
-
#default_slug ⇒ Object
Set slug name.
-
#is_rejected(attributes) ⇒ Object
Sets the validation rules to accept and save an attribute.
-
#should_generate_new_friendly_id? ⇒ Boolean
Friendly id preference on slug generation.
- #slug_uniqueness ⇒ Object
Instance Method Details
#default_slug ⇒ Object
Set slug name
It generates 4 possible slugs before falling back to FriendlyId default behaviour
36 37 38 39 40 41 |
# File 'app/models/binda/field_group.rb', line 36 def default_slug [ "#{ self.structure.name }-#{ self.name }", "#{ self.structure.name }-#{ self.name }-1", "#{ self.structure.name }-#{ self.name }-2", "#{ self.structure.name }-#{ self.name }-3" ] end |
#is_rejected(attributes) ⇒ Object
Sets the validation rules to accept and save an attribute
45 46 47 |
# File 'app/models/binda/field_group.rb', line 45 def is_rejected( attributes ) attributes['name'].blank? && attributes['field_type'].blank? end |
#should_generate_new_friendly_id? ⇒ Boolean
Friendly id preference on slug generation
Method inherited from friendly id
29 30 31 |
# File 'app/models/binda/field_group.rb', line 29 def should_generate_new_friendly_id? slug.blank? end |
#slug_uniqueness ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'app/models/binda/field_group.rb', line 49 def slug_uniqueness record_with_same_slug = self.class.where(slug: slug) if record_with_same_slug.any? && !record_with_same_slug.ids.include?(id) errors.add(:slug, I18n.t("binda.field_group.validation_message.slug", { arg1: slug })) return false else return true end end |