Class: Admin::SchoolsController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::SchoolsController
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- app/controllers/admin/schools_controller.rb
Instance Method Summary collapse
-
#confirm_migration ⇒ Object
GET /schools/1/migration/2/confirm.
-
#create ⇒ Object
POST /schools.
-
#create_migration ⇒ Object
POST /schools/1/migration/2.
-
#destroy ⇒ Object
DELETE /schools/1.
-
#edit ⇒ Object
GET /schools/1/edit.
-
#index ⇒ Object
GET /schools.
-
#initialize ⇒ SchoolsController
constructor
A new instance of SchoolsController.
-
#new ⇒ Object
GET /schools/new.
-
#new_migration ⇒ Object
GET /schools/1/migration/new.
-
#show ⇒ Object
GET /schools/1.
-
#update ⇒ Object
PUT /schools/1.
Constructor Details
#initialize ⇒ SchoolsController
Returns a new instance of SchoolsController.
15 16 17 18 |
# File 'app/controllers/admin/schools_controller.rb', line 15 def initialize super @sort_columns = %w[name city state zipcode approved] end |
Instance Method Details
#confirm_migration ⇒ Object
GET /schools/1/migration/2/confirm
94 95 96 97 |
# File 'app/controllers/admin/schools_controller.rb', line 94 def confirm_migration @school = School.where("id = ?", params[:id]).first @target_school = School.where("id = ?", params[:target_school_id]).first end |
#create ⇒ Object
POST /schools
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/admin/schools_controller.rb', line 43 def create @school = School.new(params[:school]) check_school_approved(@school, params) if @school.save redirect_to(admin_school_path(@school), :flash => { :success => "Educational institution was successfully created." }) else render :action => "new" end end |
#create_migration ⇒ Object
POST /schools/1/migration/2
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/controllers/admin/schools_controller.rb', line 100 def create_migration @school = School.where("id = ?", params[:id]).first @target_school = School.where("id = ?", params[:target_school_id]).first migrated_users = @school.migrate_users_to(@target_school) if @school && @target_school if @school && @target_school && migrated_users.size >= 0 redirect_to(admin_schools_path, :flash => { :success => "Successfully migrated #{pluralize(migrated_users.size, 'user')} " + "from #{@school.name} to #{@target_school.name}." }) else flash[:error] = "Unable to migrate users between educational institution" @target_schools = School.search(params[:search]). without_school(@school). order(sort_column + ' ' + sort_direction). paginate(:per_page => per_page, :page => params[:page]) render :new_migration end end |
#destroy ⇒ Object
DELETE /schools/1
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/admin/schools_controller.rb', line 69 def destroy @school = School.where("id = ?", params[:id]).first if @school.destroy = { :success => "Educational institution was successfully deleted." } else if @school && @school.errors[:base] && @school.errors[:base].count > 0 = { :failure => @school.errors[:base].first } else = { :failure => "Educational Insitution could not be deleted" } end end redirect_to(admin_schools_path, :flash => ) end |
#edit ⇒ Object
GET /schools/1/edit
38 39 40 |
# File 'app/controllers/admin/schools_controller.rb', line 38 def edit @school = School.where("id = ?", params[:id]).first end |
#index ⇒ Object
GET /schools
21 22 23 24 25 |
# File 'app/controllers/admin/schools_controller.rb', line 21 def index @schools = School.search(params[:search]). order(sort_column + ' ' + sort_direction). paginate(:per_page => per_page, :page => params[:page]) end |
#new ⇒ Object
GET /schools/new
33 34 35 |
# File 'app/controllers/admin/schools_controller.rb', line 33 def new @school = School.new :approved => true end |
#new_migration ⇒ Object
GET /schools/1/migration/new
84 85 86 87 88 89 90 91 |
# File 'app/controllers/admin/schools_controller.rb', line 84 def new_migration @school = School.where("id = ?", params[:id]).first @target_schools = School.search(params[:search]). without_school(@school). order(sort_column + ' ' + sort_direction). paginate(:per_page => per_page, :page => params[:page]) end |
#show ⇒ Object
GET /schools/1
28 29 30 |
# File 'app/controllers/admin/schools_controller.rb', line 28 def show @school = School.where("id = ?", params[:id]).first end |
#update ⇒ Object
PUT /schools/1
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/admin/schools_controller.rb', line 56 def update @school = School.where("id = ?", params[:id]).first check_school_approved(@school, params) if @school.update_attributes(params[:school]) redirect_to(admin_school_path(@school), :flash => { :success => "Educational institution was successfully updated." }) else render :action => "edit" end end |