Sha256: 8c425198cfa646d2b06ca384afb56c5e455a26e1076c20e3ffe479d0988184e6

Contents?: true

Size: 883 Bytes

Versions: 1

Compression:

Stored size: 883 Bytes

Contents

module Ecm::Courses
  class Course < ApplicationRecord
    # acts as list
    acts_as_list scope: :course_category

    # associations
    belongs_to :course_category

    has_many :course_dates, ->() { order(:start_at) },
             dependent: :destroy

    # friendly id
    extend FriendlyId
    friendly_id :name, use: [:slugged]

    # scopes
    default_scope { includes(:course_category).order('ecm_courses_course_categories.name, ecm_courses_courses.position ASC') }

    # validations
    validates :course_category, presence: true
    validates :locale, inclusion: { in: I18n.available_locales.map(&:to_s) }, allow_blank: true
    validates :name, presence: true

    def heading_name
      # locale_prefix = locale.blank? ? '' : "[#{locale}] "
      # "#{locale_prefix}#{name}"
      name
    end

    def to_s
      "#{course_category.name} - #{name}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ecm_courses2-0.1.0 app/models/ecm/courses/course.rb