Sha256: b7c6ae29d176666de2acc3aff8d34407dfa1898d7f3386ba63b8f9fbc960ddaa

Contents?: true

Size: 831 Bytes

Versions: 2

Compression:

Stored size: 831 Bytes

Contents

module Ecm::Courses
  class CourseCategoriesController < ApplicationController
    def self.resource_class
      CourseCategory
    end

    def index
      @course_categories = CourseCategory.all
    end

    def show
      @year  = params[:year]  ||= Time.zone.now.year
      @month = params[:month] ||= Time.zone.now.month

      @date = Date.strptime("#{@month}-#{@year}", "%m-%Y")

      @course_category = load_resource
      @courses = @course_category.courses.all
      @course_dates = @courses.reduce([]) { |cd, c| cd << c.course_dates.for_month(@date).all }.flatten
    end

    private

    def resource_class
      self.class.resource_class
    end

    def load_scope
      resource_class.includes(courses: [ :course_dates ]).friendly
    end

    def load_resource
      load_scope.find(params[:id])
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ecm_courses2-0.1.0 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-0.0.1 app/controllers/ecm/courses/course_categories_controller.rb