From 8a6fa2166e4753ed97e59b31d58db1602664197f Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Sat, 17 May 2014 13:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E4=BD=9C=E4=B8=9A=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E8=AF=A5=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E5=B9=B3=E5=9D=87=E8=AF=84=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 14 ++++++++++++++ app/models/homework_attach.rb | 10 ++++++++++ app/views/bids/_homework_list.html.erb | 14 +++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) 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)%>