Class: Admin::SchoolsController

Inherits:
AdminController
  • Object
show all
Includes:
ActionView::Helpers::TextHelper
Defined in:
app/controllers/admin/schools_controller.rb

Instance Method Summary collapse

Constructor Details

#initializeSchoolsController

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_migrationObject

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

#createObject

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_migrationObject

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

#destroyObject

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
    flash_message = { :success => "Educational institution was successfully deleted." }
  else
    if @school && @school.errors[:base] && @school.errors[:base].count > 0
      flash_message = { :failure => @school.errors[:base].first }
    else
      flash_message = { :failure => "Educational Insitution could not be deleted" }
    end
  end
  redirect_to(admin_schools_path, :flash => flash_message)
end

#editObject

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

#indexObject

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

#newObject

GET /schools/new



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

def new
  @school = School.new :approved => true
end

#new_migrationObject

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

#showObject

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

#updateObject

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