Sha256: 9dee818730131e98c3e82b85cf3cd94b658493070e87a6fa222e1693b2e5f673

Contents?: true

Size: 626 Bytes

Versions: 2

Compression:

Stored size: 626 Bytes

Contents

module Binda
	class Structure < ApplicationRecord

		# Associations
		has_many :components
		has_many :categories
		has_many :field_groups

		# Validations
		validates :name, presence: true
		validates :slug, uniqueness: true
		accepts_nested_attributes_for :field_groups, allow_destroy: true, reject_if: :is_rejected

		# Slug
		extend FriendlyId
		friendly_id :name, use: [:slugged, :finders]


		# CUSTOM METHODS
		# --------------
		# https://github.com/norman/friendly_id/issues/436
		def should_generate_new_friendly_id?
			slug.blank?
		end

		def is_rejected( attributes )
			attributes['name'].blank?
		end

	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
binda-0.0.6 app/models/binda/structure.rb
binda-0.0.5 app/models/binda/structure.rb