课程作业显示列表增加该作业平均评分

This commit is contained in:
sw 2014-05-17 13:49:27 +08:00
parent 4c6b514d03
commit 8a6fa2166e
3 changed files with 37 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -37,7 +37,19 @@
<%= link_to filename , homework_attach_path(homework)%>
</tr>
<tr>
<td colspan="1" valign="top">&nbsp;&nbsp;<strong>发布人:&nbsp; <%= link_to homework.user, user_path(homework.user)%></strong> </td>
<td colspan="1" valign="top" style="width: 300px">&nbsp;
<strong>发布人:&nbsp; <%= link_to homework.user, user_path(homework.user)%></strong>
</td>
<td>
<strong>作业评分:</strong>
<% stars_reates = homework.rates(:quality) %>
<% sum = 0 %>
<% stars_reates.each do |star_reates| %>
<% sum = sum + star_reates.stars %>
<% end %>
<% stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count %>
<%= sum * 1.0 / stars_reates_count %>
</td>
<td valign="top" align="right">
<% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.attachments[0].created_on.to_s) %>
<span class="required">迟交</span>