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