修改user.user_score为空问题的解决方式

This commit is contained in:
z9hang 2014-06-19 10:45:30 +08:00
parent 3c89de4c81
commit 9061a77221
5 changed files with 22 additions and 15 deletions

View File

@ -801,11 +801,6 @@ class UsersController < ApplicationController
else else
@user = User.find(params[:id]) @user = User.find(params[:id])
end end
if @user.user_score.nil?
us = UserScore.new
us.user_id = @user.id
us.save
end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render_404 render_404
end end

View File

@ -246,6 +246,18 @@ class UserScore < ActiveRecord::Base
Rails.logger.error "[UserScore#project] ===> Exception: #{e}." Rails.logger.error "[UserScore#project] ===> Exception: #{e}."
end 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 def total_score
score = self.influence.to_i + self.skill.to_i + self.collaboration.to_i + self.active.to_i score = self.influence.to_i + self.skill.to_i + self.collaboration.to_i + self.active.to_i

View File

@ -98,7 +98,7 @@
<!-- modified by zjc 新得分显示 --> <!-- modified by zjc 新得分显示 -->
<tr><td class="score"> <tr><td class="score">
<%= l(:label_user_grade)%>: <%= 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', :action => 'show_new_score',
:remote => true, :remote => true,
:id => @user.id :id => @user.id

View File

@ -28,7 +28,7 @@
<div> = <%= l(:label_user_score_of_collaboration) %> + <%= l(:label_user_score_of_influence) %> + <div> = <%= l(:label_user_score_of_collaboration) %> + <%= l(:label_user_score_of_influence) %> +
<%= l(:label_user_score_of_skill)%> + <%= l(:label_user_score_of_active) %></div> <%= l(:label_user_score_of_skill)%> + <%= l(:label_user_score_of_active) %></div>
<!-- <div>&nbsp;&nbsp;&nbsp;+ <%= l(:label_user_score_of_influence) %></div> --> <!-- <div>&nbsp;&nbsp;&nbsp;+ <%= l(:label_user_score_of_influence) %></div> -->
<div> = <%= 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 %> <div> = <%= 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.skill.nil? ? 0:@user.user_score.skill).to_f %> + <%= format("%.2f" , @user.user_score.active.nil? ? 0:@user.user_score.active).to_f %></div> + <%= 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 %></div>
<div> = <%= format("%.2f" ,@user.user_score.total_score.nil? ? 0:@user.user_score.total_score).to_f %></div> <div> = <%= format("%.2f" ,@user.user_score_attr.total_score.nil? ? 0:@user.user_score_attr.total_score).to_f %></div>
<!-- end --> <!-- end -->

View File

@ -38,7 +38,7 @@
<td> <td>
<table> <table>
<tr class="info_font"><td><%= l(:label_user_score) %></td></tr> <tr class="info_font"><td><%= l(:label_user_score) %></td></tr>
<tr class="buttons_for_score" style="margin-top:30px;margin-left:144px"><td><span style="color:#ec6300"><%= format("%.2f" , @user.user_score.total_score).to_f %></span></td></tr> <tr class="buttons_for_score" style="margin-top:30px;margin-left:144px"><td><span style="color:#ec6300"><%= format("%.2f" , @user.user_score_attr.total_score).to_f %></span></td></tr>
</table> </table>
</td> </td>
</tr> </tr>
@ -49,23 +49,23 @@
<table style="border-bottom: solid 0px #80a6d2;" width="100%"> <table style="border-bottom: solid 0px #80a6d2;" width="100%">
<tr> <tr>
<%= l(:label_user_score) %> : <%= l(:label_user_score) %> :
<%= format("%.2f" , @user.user_score.total_score).to_f %> <%= format("%.2f" , @user.user_score_attr.total_score).to_f %>
</tr><br> </tr><br>
<tr> <tr>
<%= l(:label_user_score_of_collaboration) %> : <%= 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 %>
</tr><br> </tr><br>
<tr> <tr>
<%= l(:label_user_score_of_influence) %> : <%= 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 %>
</tr><br> </tr><br>
<tr> <tr>
<%= l(:label_user_score_of_skill) %> : <%= 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 %>
</tr><br> </tr><br>
<tr> <tr>
<%= l(:label_user_score_of_active) %> <%= 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 %>
</tr><br> </tr><br>
</table> </table>