diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index cf0276d97..01578eab3 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -23,6 +23,7 @@ class HomeworkAttachController < ApplicationController @jour = @jours[@offset, @limit] end + #删除留言 def destroy @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) respond_to do |format| @@ -30,6 +31,7 @@ class HomeworkAttachController < ApplicationController end end + #添加留言 def addjours @homework = HomeworkAttach.find(params[:jour_id]) @homework.addjours User.current.id, params[:new_form][:user_message],0 @@ -43,5 +45,17 @@ class HomeworkAttachController < ApplicationController format.js end end + + #获取指定作业的平均得分 + def score + #stars_reates = @homework.rates(:quality) + #percent = 0 + #stars_reates.each do |star_reates| + # percent = percent + star_reates.stars + #end + #stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count + #result = percent * 1.0 / stars_reates_count + #result + end end diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb index 2e5ade8b3..d112ead50 100644 --- a/app/models/homework_attach.rb +++ b/app/models/homework_attach.rb @@ -14,4 +14,14 @@ class HomeworkAttach < ActiveRecord::Base jfm.save jfm end + + def score + stars_reates = self.rates(:quality) + percent = 0 + stars_reates.each do |star_reates| + percent = percent + star_reates.stars + end + result = percent * 1.0 / stars_reates.count + result + end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index f3658cd2a..35c414699 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -37,7 +37,19 @@ <%= link_to filename , homework_attach_path(homework)%>