Class: Manage::SchoolsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/manage/schools_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#limit_admin_access, #logged_in

Instance Method Details

#createObject



25
26
27
28
29
# File 'app/controllers/manage/schools_controller.rb', line 25

def create
  @school = ::School.new(school_params)
  @school.save
  respond_with(:manage, @school, location: manage_schools_path)
end

#datatableObject



9
10
11
# File 'app/controllers/manage/schools_controller.rb', line 9

def datatable
  render json: SchoolDatatable.new(view_context)
end

#destroyObject



36
37
38
39
# File 'app/controllers/manage/schools_controller.rb', line 36

def destroy
  @school.destroy
  respond_with(:manage, @school, location: manage_schools_path)
end

#editObject



22
23
# File 'app/controllers/manage/schools_controller.rb', line 22

def edit
end

#indexObject



6
7
# File 'app/controllers/manage/schools_controller.rb', line 6

def index
end

#mergeObject



41
42
# File 'app/controllers/manage/schools_controller.rb', line 41

def merge
end

#newObject



17
18
19
20
# File 'app/controllers/manage/schools_controller.rb', line 17

def new
  @school = ::School.new
  respond_with(:manage, @school)
end

#perform_mergeObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/manage/schools_controller.rb', line 44

def perform_merge
  new_school_name = params[:school][:id]
  if new_school_name.blank?
    flash[:notice] = "Error: Must include the new school to merge into!"
    render :merge
    return
  end

  new_school = School.where(name: new_school_name).first
  if new_school.blank?
    flash[:notice] = "Error: School doesn't exist: #{new_school_name}"
    render :merge
    return
  end

  Questionnaire.where(school_id: @school.id).each do |q|
    q.update_attribute(:school_id, new_school.id)
  end

  SchoolNameDuplicate.create(name: @school.name, school_id: new_school.id)

  @school.reload

  if @school.questionnaire_count < 1
    @school.destroy
  else
    flash[:notice] = "*** Old school NOT deleted: #{@school.questionnaire_count} questionnaires still associated!\n"
  end

  redirect_to manage_schools_path(new_school)
end

#showObject



13
14
15
# File 'app/controllers/manage/schools_controller.rb', line 13

def show
  respond_with(:manage, @school)
end

#updateObject



31
32
33
34
# File 'app/controllers/manage/schools_controller.rb', line 31

def update
  @school.update_attributes(school_params)
  respond_with(:manage, @school, location: manage_schools_path)
end