Sha256: e51fdfc36156cffc73e55cd9536aa871051fe70b0918416b24359ffabf80c981

Contents?: true

Size: 1020 Bytes

Versions: 10

Compression:

Stored size: 1020 Bytes

Contents

module Ecm::Courses
  class CourseCategoriesController < Ecm::Courses::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

      respond_to do |format|
        format.html
        format.ics do
          send_data @course_category.to_icalendar.to_ical, type: 'text/calendar'
        end
      end
    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

10 entries across 10 versions & 1 rubygems

Version Path
ecm_courses2-1.1.4 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-1.1.3 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-1.1.2 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-1.1.1 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-1.1.0 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-1.0.3 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-1.0.2 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-1.0.1 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-1.0.0 app/controllers/ecm/courses/course_categories_controller.rb
ecm_courses2-0.2.4 app/controllers/ecm/courses/course_categories_controller.rb