合并user_score属性
This commit is contained in:
parent
174c5556a0
commit
db61ecc255
|
@ -137,7 +137,7 @@ class User < Principal
|
|||
has_one :user_extensions,:dependent => :destroy
|
||||
## end
|
||||
|
||||
default_scope -> { includes(:user_extensions, :user_score) }
|
||||
# default_scope -> { includes(:user_extensions, :user_score) }
|
||||
scope :teacher, -> {
|
||||
joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::TEACHER)
|
||||
}
|
||||
|
@ -201,6 +201,7 @@ class User < Principal
|
|||
|
||||
# ======================================================================
|
||||
# 集中处理 User 扩展表为空的问题
|
||||
# 合并 user_score 属性
|
||||
validate :valid_user_extensions
|
||||
after_save :save_user_extensions
|
||||
|
||||
|
@ -208,21 +209,32 @@ class User < Principal
|
|||
self.user_extensions ||= UserExtensions.new
|
||||
end
|
||||
|
||||
def respond_to?(m, include_private = false)
|
||||
flag = UserExtensions.instance_methods.include? m.to_sym
|
||||
if flag
|
||||
flag
|
||||
else
|
||||
super
|
||||
def user_score_attr
|
||||
self.user_score ||= UserScore.new
|
||||
end
|
||||
|
||||
alias_method :ori_respond_to?, :respond_to?
|
||||
def respond_to?(m, include_private = false)
|
||||
flag = false
|
||||
flag = ori_respond_to? m.to_sym unless flag
|
||||
flag = UserExtensions.new.respond_to? m.to_sym unless flag
|
||||
flag = UserScore.new.respond_to? m.to_sym unless flag
|
||||
|
||||
flag
|
||||
end
|
||||
|
||||
def method_missing m, *args, &block
|
||||
if extensions.respond_to? m.to_sym
|
||||
self.class.send :define_method, m.to_sym, *args do
|
||||
self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block|
|
||||
self.extensions.__send__ m.to_sym, *args
|
||||
end
|
||||
__send__ m.to_sym, *args, &block
|
||||
__send__ "_meta_#{m}".to_sym, *args, &block
|
||||
|
||||
elsif user_score_attr.respond_to? m.to_sym
|
||||
self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block|
|
||||
self.user_score_attr.__send__ m.to_sym, *args
|
||||
end
|
||||
__send__ "_meta_#{m}".to_sym, *args, &block
|
||||
|
||||
else
|
||||
super
|
||||
|
@ -241,6 +253,7 @@ class User < Principal
|
|||
|
||||
def save_user_extensions
|
||||
self.extensions.save
|
||||
self.user_score_attr.save
|
||||
end
|
||||
# 集中处理 User 扩展表为空的问题 < end
|
||||
# ======================================================================
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
<!-- added by bai -->
|
||||
<% unless @user.id == 1%>
|
||||
<% messages_count = @user.messages.count %>
|
||||
<% messages_score = messages_count * 0.05%>
|
||||
<% finall_messages_score = messages_score %>
|
||||
<% end %>
|
||||
|
||||
<% journals_count = @user.journals.count %>
|
||||
<% journals_score = journals_count * 0.1 %>
|
||||
|
@ -73,31 +71,6 @@
|
|||
|
||||
</div>
|
||||
|
||||
<!-- <div class="inf_user_image">
|
||||
<ul>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score), {:controller => 'users', :action => 'score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_user_score).to_f %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score_of_topic), {:controller => 'users', :action => 'topic_score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_messages_score).to_f %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score_of_project), {:controller => 'users', :action => 'project_score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_user_project_score).to_f %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score_of_activity), {:controller => 'users', :action => 'activity_score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_activity_score).to_f %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to l(:label_user_score_of_influence), {:controller => 'users', :action => 'influence_score_index', :remote => true} %> :
|
||||
<%= format("%.2f" , finall_influence_score).to_f %>
|
||||
</li>
|
||||
</ul>
|
||||
</div> -->
|
||||
<div id="show_score_detail", style="padding-left: 6px">
|
||||
<%= render :partial => 'users/score_index', :locals => {:index => 0 } %>
|
||||
</div>
|
||||
<!-- end -->
|
|
@ -1,5 +1,3 @@
|
|||
<!-- added by bai -->
|
||||
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'users/show_score') %>');
|
||||
showModal('ajax-modal', '400px');
|
||||
$('#ajax-modal').addClass('new-watcher');
|
||||
<!-- end -->
|
Loading…
Reference in New Issue