Class: Gaku::StudentsController
Instance Method Summary
collapse
#remove_picture, #set_picture
#class_name, #class_name_minus_enrollment, #class_name_underscored, #class_name_underscored_plural, #enrollment_param
#resolve_layout
Instance Method Details
#advanced_search ⇒ Object
54
55
56
57
58
59
60
|
# File 'app/controllers/gaku/students_controller.rb', line 54
def advanced_search
@prefilled = session[:q].to_json
set_countries
set_enrollment_statuses
@search = Student.active.search(params[:q])
@students = @search.result(distinct: true)
end
|
#chosen ⇒ Object
45
46
47
|
# File 'app/controllers/gaku/students_controller.rb', line 45
def chosen
set_selected_students
end
|
#clear_search ⇒ Object
49
50
51
52
|
# File 'app/controllers/gaku/students_controller.rb', line 49
def clear_search
session[:q] = nil
redirect_to students_path
end
|
#create ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/controllers/gaku/students_controller.rb', line 28
def create
@student = Student.new(student_params)
if @student.save
if params[:student][:enrollments]
@student.class_group_enrollments.create(enrollmentable_id: params[:student][:enrollments][:enrollmentable_id])
end
@count = Student.count
respond_with @student, location: [:edit, @student]
else
render :new
end
end
|
#destroy ⇒ Object
100
101
102
103
104
|
# File 'app/controllers/gaku/students_controller.rb', line 100
def destroy
@student.destroy
@count = Student.count
respond_with @student
end
|
#edit ⇒ Object
92
93
94
|
# File 'app/controllers/gaku/students_controller.rb', line 92
def edit
respond_with @student
end
|
#index ⇒ Object
41
42
43
|
# File 'app/controllers/gaku/students_controller.rb', line 41
def index
search
end
|
#new ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/gaku/students_controller.rb', line 14
def new
@enrolled_status = EnrollmentStatus.where(code: 'enrolled').first_or_create!
@last_student = Student.last
@student = Student.new
if @last_student
@student.admitted = @last_student.admitted
@student.enrollment_status_code = @last_student.enrollment_status_code
else
@student.enrollment_status_code = @enrolled_status.code
end
respond_with @student
end
|
#search ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/controllers/gaku/students_controller.rb', line 62
def search
session[:q] = params[:q] if session[:q] != params[:q] && params[:q]
if session[:q]
search_unscoped = search_unscoped_params.any? { |k| session[:q].key?(k) }
if search_unscoped == true
@search = Student.includes(index_includes).search(session[:q])
else
@search = Student.includes(index_includes).active.search(session[:q])
end
sort_by_age = sort_age_params.any? { |k| session[:q].key?(k) }
if sort_by_age == true
@search.sorts = 'birth_date desc'
else
@search.sorts = 'created_at desc'
end
else
@search = Student.includes(index_includes).active.search(params[:q])
end
results = @search.result(distinct: true)
@students = results.page(params[:page])
@count = results.count
render :index, layout: 'gaku/layouts/index'
end
|
#show ⇒ Object
96
97
98
|
# File 'app/controllers/gaku/students_controller.rb', line 96
def show
respond_with @student
end
|
#update ⇒ Object
106
107
108
109
|
# File 'app/controllers/gaku/students_controller.rb', line 106
def update
@student.update(student_params)
respond_with @student, location: [:edit, @student]
end
|