application_controller.rb 713 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
Zac Wood's avatar
Zac Wood committed
4
5
6
7
8
9
  before_action :set_semester, :set_cookies, :set_cart

  def set_semester
    @semester = if cookies.key?(:semester_id)
                  Semester.find_by(id: cookies[:semester_id])
                else
Zac Wood's avatar
Zac Wood committed
10
                  sem = Semester.first
Zac Wood's avatar
Zac Wood committed
11
12
                  cookies[:semester_id] = sem.id
                  sem
Zac Wood's avatar
Zac Wood committed
13
14
                end
  end
15
16

  def set_cart
17
    @cart = JSON.parse(cookies[:cart])
Zac Wood's avatar
Zac Wood committed
18
  end
19

Zac Wood's avatar
Zac Wood committed
20
21
  def set_cookies
    cookies[:crns] = "" if cookies[:crns].nil?
Zac Wood's avatar
Zac Wood committed
22
    cookies[:section_ids] = "" if cookies[:section_ids].nil?
23
    cookies[:cart] = "[]" if cookies[:cart].nil?
24
  end
Zac Wood's avatar
Zac Wood committed
25
end