From 9061a7722121eb5764ae5847e102f74fda7f32b8 Mon Sep 17 00:00:00 2001 From: z9hang Date: Thu, 19 Jun 2014 10:45:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9user.user=5Fscore=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E9=97=AE=E9=A2=98=E7=9A=84=E8=A7=A3=E5=86=B3=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 5 ----- app/models/user_score.rb | 12 ++++++++++++ app/views/layouts/base_users.html.erb | 2 +- app/views/users/_score_new_index.html.erb | 6 +++--- app/views/users/_show_new_score.html.erb | 12 ++++++------ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ae5b1829..494b8333 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -801,11 +801,6 @@ class UsersController < ApplicationController else @user = User.find(params[:id]) end - if @user.user_score.nil? - us = UserScore.new - us.user_id = @user.id - us.save - end rescue ActiveRecord::RecordNotFound render_404 end diff --git a/app/models/user_score.rb b/app/models/user_score.rb index 0e355b79..07c66985 100644 --- a/app/models/user_score.rb +++ b/app/models/user_score.rb @@ -246,6 +246,18 @@ class UserScore < ActiveRecord::Base Rails.logger.error "[UserScore#project] ===> Exception: #{e}." end + #获取用户的user_score + def self.score(user) + if user.user_score.nil? + us = UserScore.new + us.user_id = user.id + us.save + us + else + user.user_score + end + end + #计算总得分 def total_score score = self.influence.to_i + self.skill.to_i + self.collaboration.to_i + self.active.to_i diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index 193171e6..895f83bb 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -98,7 +98,7 @@ <%= l(:label_user_grade)%>: - <%= link_to(format("%.2f" , @user.user_score.total_score).to_f, {:controller => 'users', + <%= link_to(format("%.2f" , @user.user_score_attr.total_score).to_f, {:controller => 'users', :action => 'show_new_score', :remote => true, :id => @user.id diff --git a/app/views/users/_score_new_index.html.erb b/app/views/users/_score_new_index.html.erb index 10fa1e84..43687aa7 100644 --- a/app/views/users/_score_new_index.html.erb +++ b/app/views/users/_score_new_index.html.erb @@ -28,7 +28,7 @@
= <%= l(:label_user_score_of_collaboration) %> + <%= l(:label_user_score_of_influence) %> + <%= l(:label_user_score_of_skill)%> + <%= l(:label_user_score_of_active) %>
-
= <%= format("%.2f" ,@user.user_score.collaboration.nil? ? 0:@user.user_score.collaboration).to_f %> + <%= format("%.2f" , @user.user_score.influence.nil? ? 0:@user.user_score.influence ).to_f %> - + <%= format("%.2f" , @user.user_score.skill.nil? ? 0:@user.user_score.skill).to_f %> + <%= format("%.2f" , @user.user_score.active.nil? ? 0:@user.user_score.active).to_f %>
-
= <%= format("%.2f" ,@user.user_score.total_score.nil? ? 0:@user.user_score.total_score).to_f %>
+
= <%= format("%.2f" ,@user.user_score_attr.collaboration.nil? ? 0:@user.user_score_attr.collaboration).to_f %> + <%= format("%.2f" , @user.user_score_attr.influence.nil? ? 0:@user.user_score_attr.influence ).to_f %> + + <%= format("%.2f" , @user.user_score_attr.skill.nil? ? 0:@user.user_score_attr.skill).to_f %> + <%= format("%.2f" , @user.user_score_attr.active.nil? ? 0:@user.user_score_attr.active).to_f %>
+
= <%= format("%.2f" ,@user.user_score_attr.total_score.nil? ? 0:@user.user_score_attr.total_score).to_f %>
diff --git a/app/views/users/_show_new_score.html.erb b/app/views/users/_show_new_score.html.erb index d22150a8..3fd5f105 100644 --- a/app/views/users/_show_new_score.html.erb +++ b/app/views/users/_show_new_score.html.erb @@ -38,7 +38,7 @@ - +
<%= l(:label_user_score) %>
<%= format("%.2f" , @user.user_score.total_score).to_f %>
<%= format("%.2f" , @user.user_score_attr.total_score).to_f %>
@@ -49,23 +49,23 @@ <%= l(:label_user_score) %> : - <%= format("%.2f" , @user.user_score.total_score).to_f %> + <%= format("%.2f" , @user.user_score_attr.total_score).to_f %>
<%= l(:label_user_score_of_collaboration) %> : - <%= format("%.2f" , @user.user_score.collaboration.nil? ? 0:@user.user_score.collaboration).to_f %> + <%= format("%.2f" , @user.user_score_attr.collaboration.nil? ? 0:@user.user_score_attr.collaboration).to_f %>
<%= l(:label_user_score_of_influence) %> : - <%= format("%.2f" , @user.user_score.influence.nil? ? 0:@user.user_score.influence).to_f %> + <%= format("%.2f" , @user.user_score_attr.influence.nil? ? 0:@user.user_score_attr.influence).to_f %>
<%= l(:label_user_score_of_skill) %> : - <%= format("%.2f" , @user.user_score.skill.nil? ? 0:@user.user_score.skill).to_f %> + <%= format("%.2f" , @user.user_score_attr.skill.nil? ? 0:@user.user_score_attr.skill).to_f %>
<%= l(:label_user_score_of_active) %> : - <%= format("%.2f" , @user.user_score.active.nil? ? 0:@user.user_score.active).to_f %> + <%= format("%.2f" , @user.user_score_attr.active.nil? ? 0:@user.user_score_attr.active).to_f %>