application_controller.rb 609 Bytes
Newer Older
1
# Configures the application.
Zac Wood's avatar
Zac Wood committed
2
class ApplicationController < ActionController::Base
Zac Wood's avatar
Zac Wood committed
3
  protect_from_forgery with: :null_session
4
  before_action :set_cookies, :set_cart, :set_semester
5
6
7
8
9
10

  def set_cart
    @cart = cookies[:ids].split(',').map do |crn|
      CourseSection.find_by_crn crn
    end
  end
Zac Wood's avatar
Zac Wood committed
11
12
13
14

  def set_cookies
    cookies[:ids] = "" if cookies[:ids].nil?
  end
15
16
17
18
19
20
21
22

  def set_semester
    @semester = if params.key?(:semester_id)
                  Semester.find_by(id: params[:semester_id])
                else
                  Semester.find_by(season: 'Fall', year: '2018')
                end
  end
Zac Wood's avatar
Zac Wood committed
23
end