Sha256: 25ee051cf12cbce471258f507e80c81f96b7530429711c74a2a42299f0018085

Contents?: true

Size: 641 Bytes

Versions: 2

Compression:

Stored size: 641 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.3 app/models/binda/structure.rb
binda-0.0.2 app/models/binda/structure.rb