sessions_controller.rb 785 Bytes
Newer Older
Zac Wood's avatar
Zac Wood committed
1
2
class SessionsController < ApplicationController
  def update
3
    update_cookie :crns
Zac Wood's avatar
Zac Wood committed
4
    update_cookie :section_ids
5
    update_cookie :semester_id
Zac Wood's avatar
Zac Wood committed
6
7
8
9

    head :ok
  end

10
  def cart
11
    section_id = params[:section_id]
Zac Wood's avatar
Zac Wood committed
12

13
14
15
16
    if @cart.include?(section_id)
      @cart.reject! { |id| section_id == id }
    else
      @cart << section_id
17
18
    end

19
20
    cookies[:cart] = @cart.to_json
    render json: @cart.to_json
21
22
  end

Zac Wood's avatar
Zac Wood committed
23
24
25
26
27
28
29
30
31
32
  def add_bulk
    crns = params[:crns].split(',')
    crns.each { |crn|
      section_id = CourseSection.find_by_crn(crn).id.to_s
      @cart << section_id unless @cart.include?(section_id)
    }
    cookies[:cart] = @cart.to_json
    redirect_to schedule_path
  end

Zac Wood's avatar
Zac Wood committed
33
34
35
36
37
38
  private

  def update_cookie(sym)
    cookies[sym] = params[sym] unless params[sym].nil?
  end
end