修改user.user_score为空问题的解决方式
This commit is contained in:
parent
3c89de4c81
commit
9061a77221
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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> + <%= l(:label_user_score_of_influence) %></div> -->
|
<!-- <div> + <%= 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 -->
|
||||||
|
|
|
@ -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>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue