application_controller.rb 635 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
  before_action :set_semester, :set_cookies, :set_cart

  def set_semester
7
8
    redirect_to(url_for(params.permit(params.keys).merge(semester_id: Semester.first.id))) unless params.key?(:semester_id)
    @semester = Semester.find_by_id params[:semester_id]
Zac Wood's avatar
Zac Wood committed
9
  end
10
11

  def set_cart
12
    @cart = JSON.parse(cookies[:cart])
Zac Wood's avatar
Zac Wood committed
13
  end
14

Zac Wood's avatar
Zac Wood committed
15
16
  def set_cookies
    cookies[:crns] = "" if cookies[:crns].nil?
Zac Wood's avatar
Zac Wood committed
17
    cookies[:section_ids] = "" if cookies[:section_ids].nil?
18
    cookies[:cart] = "[]" if cookies[:cart].nil?
19
  end
Zac Wood's avatar
Zac Wood committed
20
end