Class: Manage::SchoolsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#json_request?, #limit_write_access_to_admins, #logged_in, #require_admin_or_limited_admin, #require_admin_or_limited_admin_or_event_tracking, #response_view_or_errors

Instance Method Details

#createObject



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

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

#datatableObject



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

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

#destroyObject



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

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

#editObject



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

def edit
end

#indexObject



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

def index
  respond_with(:manage, School.all)
end

#mergeObject



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

def merge
end

#newObject



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

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

#perform_mergeObject



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
75
# File 'app/controllers/manage/schools_controller.rb', line 45

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_school_path(new_school)
end

#showObject



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

def show
  respond_with(:manage, @school)
end

#updateObject



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

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