Class: Manage::SchoolsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Manage::SchoolsController
- Defined in:
- app/controllers/manage/schools_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #datatable ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #merge ⇒ Object
- #new ⇒ Object
- #perform_merge ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
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 |
#datatable ⇒ Object
10 11 12 |
# File 'app/controllers/manage/schools_controller.rb', line 10 def datatable render json: SchoolDatatable.new(view_context) end |
#destroy ⇒ Object
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 |
#edit ⇒ Object
23 24 |
# File 'app/controllers/manage/schools_controller.rb', line 23 def edit end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/manage/schools_controller.rb', line 6 def index respond_with(:manage, School.all) end |
#merge ⇒ Object
42 43 |
# File 'app/controllers/manage/schools_controller.rb', line 42 def merge end |
#new ⇒ Object
18 19 20 21 |
# File 'app/controllers/manage/schools_controller.rb', line 18 def new @school = ::School.new respond_with(:manage, @school) end |
#perform_merge ⇒ Object
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 |
#show ⇒ Object
14 15 16 |
# File 'app/controllers/manage/schools_controller.rb', line 14 def show respond_with(:manage, @school) end |
#update ⇒ Object
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 |