From e48edac988c05ce9bce6b43993d2c4fabd89f5b4 Mon Sep 17 00:00:00 2001 From: wanglinchun Date: Wed, 30 Apr 2014 08:07:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E8=B5=9B=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=89=93=E5=88=86=E7=BB=86?= =?UTF-8?q?=E8=8A=82--=E5=88=9D=E7=BA=A7=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/softapplications_controller.rb | 17 +++++++++++++++++ app/views/softapplications/index.html.erb | 3 ++- app/views/softapplications/show.html.erb | 13 ++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index c040d2af3..281f6216d 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -40,8 +40,25 @@ class SoftapplicationsController < ApplicationController # GET /softapplications/1 # GET /softapplications/1.json + + def percent_of(num, percent) + num.to_f / percent.to_f * 100.0 + end + def show @softapplication = Softapplication.find(params[:id]) + # 打分统计 + stars_reates = @softapplication. + rates(:quality) + stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count + stars_status = stars_reates.select("stars, count(*) as scount"). + group("stars") + + @stars_status_map = Hash.new(0.0) + stars_status.each do |star_status| + @stars_status_map["star#{star_status.stars.to_i}".to_sym] = + percent_of(star_status.scount, stars_reates_count).to_s + "%" + end @jours = @softapplication.journals_for_messages.order('created_on DESC') @image_results = [] @softapplication.attachments.each do |f| diff --git a/app/views/softapplications/index.html.erb b/app/views/softapplications/index.html.erb index df5ea1921..950e822a3 100644 --- a/app/views/softapplications/index.html.erb +++ b/app/views/softapplications/index.html.erb @@ -49,7 +49,8 @@
<%= image_tag('/images/app1.png')%>
<%= softapplication.description.truncate(95, omission: '...') %>
-

所属竞赛:<%#= contest ? link_to(contest.name, show_softapplication_contest_path()) : '尚未加入竞赛'%>

+ <%contest = softapplication.contests.first%> +

所属竞赛:<%= contest ? link_to(contest.name, show_softapplication_contest_path(contest) ) : '尚未加入竞赛'%>

所属类别:<%= softapplication.app_type_name %>

系统支持:<%= softapplication.android_min_version_available %>

diff --git a/app/views/softapplications/show.html.erb b/app/views/softapplications/show.html.erb index 046705081..06cc95e30 100644 --- a/app/views/softapplications/show.html.erb +++ b/app/views/softapplications/show.html.erb @@ -72,7 +72,18 @@
- +
+<% 100.step(20,-20) do |star| %> +
+
+
+
+
+
+<%= @stars_status_map["star#{(star/20).to_s}".to_sym] %> +
+<% end %> +
软件评论:
评分: <%= rating_for @softapplication, dimension: :quality, class: 'rateable div_inline' %>