Sha256: 2a3507a8245856cc6d7c35516444b18b237524132301946f3ba9e9926bf76712
Contents?: true
Size: 1018 Bytes
Versions: 2
Compression:
Stored size: 1018 Bytes
Contents
module Binda class FieldGroup < ApplicationRecord # Associations belongs_to :structure # use destroy not delete_all otherwise the field settings # won't be able to delete all their dependent content has_many :field_settings, dependent: :delete_all # Validations validates :name, presence: true validates :slug, uniqueness: true accepts_nested_attributes_for :field_settings, allow_destroy: true, reject_if: :is_rejected # Slug extend FriendlyId friendly_id :default_slug, use: [:slugged, :finders] # CUSTOM METHODS # -------------- # https://github.com/norman/friendly_id/issues/436 def should_generate_new_friendly_id? slug.blank? end 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 def is_rejected( attributes ) attributes['name'].blank? && attributes['field_type'].blank? end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
binda-0.0.3 | app/models/binda/field_group.rb |
binda-0.0.2 | app/models/binda/field_group.rb |