Class: Manage::SchoolsController
Instance Method Summary
collapse
#limit_admin_access, #logged_in
Instance Method Details
#create ⇒ Object
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
|
#datatable ⇒ Object
9
10
11
|
# File 'app/controllers/manage/schools_controller.rb', line 9
def datatable
render json: SchoolDatatable.new(view_context)
end
|
#destroy ⇒ Object
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
|
#edit ⇒ Object
22
23
|
# File 'app/controllers/manage/schools_controller.rb', line 22
def edit
end
|
#index ⇒ Object
6
7
|
# File 'app/controllers/manage/schools_controller.rb', line 6
def index
end
|
#merge ⇒ Object
41
42
|
# File 'app/controllers/manage/schools_controller.rb', line 41
def merge
end
|
#new ⇒ Object
17
18
19
20
|
# File 'app/controllers/manage/schools_controller.rb', line 17
def new
@school = ::School.new
respond_with(:manage, @school)
end
|
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
|
#show ⇒ Object
13
14
15
|
# File 'app/controllers/manage/schools_controller.rb', line 13
def show
respond_with(:manage, @school)
end
|
#update ⇒ Object
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
|