instructors_controller.rb 631 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1 2
class InstructorsController < ApplicationController
  def index
3
    @instructors = Instructor.all
Zac Wood's avatar
Zac Wood committed
4 5 6
  end

  def show
Zac Wood's avatar
Zac Wood committed
7
    @instructor = Instructor.find_by_id(params[:id])
8

Zac Wood's avatar
Zac Wood committed
9
    # find the courses being taught this semester
10 11
    sections = CourseSection.where(instructor: @instructor, semester: @semester)
    @courses = Course.build_set(sections)
Zac Wood's avatar
Zac Wood committed
12

13 14 15 16 17 18
    # build the list of courses the instructor has taught in the past
    @past = []
    @instructor.course_sections.map(&:course).each do |c|
      @past << c unless @past.select { |past| past.full_name == c.full_name }.count.positive?
    end
    @past.sort_by!(&:full_name)
19
  end
Zac Wood's avatar
Zac Wood committed
20
end