Sha256: 64dbd16a049b7ea61076d543cbfe4c2af9cb418f00beda9dbe7468364ccce495
Contents?: true
Size: 971 Bytes
Versions: 4
Compression:
Stored size: 971 Bytes
Contents
# frozen_string_literal: true module Archangel ## # Collection model # class Collection < ApplicationRecord acts_as_paranoid before_validation :parameterize_slug after_destroy :column_reset validates :name, presence: true validates :slug, presence: true, uniqueness: { scope: :site_id } has_many :entries, inverse_of: :collection has_many :fields, inverse_of: :collection accepts_nested_attributes_for :fields, reject_if: :all_blank, allow_destroy: true belongs_to :site has_many :entries has_many :fields ## # Overwrite resource id to `slug` # # @return [String] the aliased resource param # def to_param slug end protected def parameterize_slug self.slug = slug.to_s.downcase.parameterize end def column_reset now = Time.current.to_i self.slug = "#{now}_#{slug}" save end end end
Version data entries
4 entries across 4 versions & 1 rubygems