diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index c0df0699c..923225606 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -412,7 +412,7 @@ class BidsController < ApplicationController #增加作业按评分排序, @homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id) AS score - FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY score DESC") + FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY score DESC",:include => [:attachments]) if params[:student_id].present? @temp = [] @homework_list.each do |pro| diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index fb0a269e6..326ea8739 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -168,4 +168,15 @@ module CoursesHelper seem_count = homework.rates(:quality).where("rater_id = ?",User.current).count seem_count > 0 end + + #获取指定作业的平均评分 + def homework_score homework + 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 + format("%.2f", sum * 1.0 / stars_reates_count) + end end diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 48f1c150d..a7d65ea43 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -43,14 +43,6 @@ <% else %> <% homework_filename = attachment.filename %> <% end %> - <% end %> <% else %> <% homework_filename = homework.name %> @@ -83,13 +75,7 @@ 作业评分: - <% 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 %> - <%= format("%.2f", sum * 1.0 / stars_reates_count) %> + <%= homework_score homework %> <% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.created_at.to_s) %> @@ -104,8 +90,7 @@ <% end %> - <% if (User.current == homework.user) || (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && - (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',3,7, 9)).size >0) %> + <% if (User.current == homework.user) || is_teacher %> <%= link_to l(:button_edit), edit_homework_attach_path(homework) %> <%= link_to(l(:label_bid_respond_delete), homework, method: :delete, :confirm => l(:text_are_you_sure)) %> diff --git a/app/views/layouts/base_homework.html.erb b/app/views/layouts/base_homework.html.erb index 81a8b0861..62c7d482d 100644 --- a/app/views/layouts/base_homework.html.erb +++ b/app/views/layouts/base_homework.html.erb @@ -22,27 +22,27 @@ <% course = Course.find_by_extra(project.identifier) %>
-
- <%= render :partial => 'layouts/base_header'%> +
+ <%= render :partial => 'layouts/base_header'%>
-
+
- + - -
高校课程实践社区 <%= l(:label_user_location) %> :
<%= link_to request.host()+"/courses", :controller => 'projects', :action => 'course'%>

<%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> > - <%= link_to(@bid.courses.first.name.to_s, homework_project_path(@bid.courses.first)) if @bid.courses.first%> > +

<%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> > + <%= link_to(@bid.courses.first.name.to_s, homework_project_path(@bid.courses.first)) if @bid.courses.first%> > <%=link_to(@bid.name, respond_path(@bid)) %>

+
- +