/
students_controller.rb
62 lines (56 loc) · 1.55 KB
/
students_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class StudentsController < ApplicationController
layout"application", :except => [ :print ]
#获取学生信息
def get_all_students
people = Person.all.collect &fields_provider
render_json people
end
def update_student_comment
s = Student.find(params[:id])
if s.update_attribute(:comment, params[:comment])
render_json "success"
else
render_error s.errors
end
end
def student_total_score
render_json Student.find(params[:s_id]).total_score_by_grade
end
#删除学生
def destroy_student
Person.find(params[:id]).delete
render_json "success"
end
#保存学生更新
def update_student
data = {
:number => params["number"],
:sex => params["sex"],
:phone => params["phone"],
:home => params["home"],
:name => params["name"],
:classes_id => params["classes_id"]
}
data["image"] = params["photo"] if(params["photo"])
if params["id"] == "save"
params[:type] == "Student"? Student.create(data) : Teacher.create(data)
else
Person.find(params["id"]).update_attributes!(data)
end
render_json "success", "text/html"
rescue => e
render_error e.message,'text/html'
end
def update_score
params[:jsonData].each do |j|
j.delete("course/name")
end
Student.find(params[:studentId]).update_attributes({ :course_scores_attributes => params[:jsonData]})
render_json "success"
rescue => e
render_error e.message
end
def print
@student = Student.find(params[:id])
end
end