diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index c040d2af..281f6216 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 df5ea192..950e822a 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 04670508..06cc95e3 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' %>