把所有user_extensions的逻辑移到了user中,业务代码还没有修改,下一步是user_score和projectxxx,先测测效果

This commit is contained in:
yanxd 2014-06-03 16:41:12 +08:00
parent 4b119e2f00
commit 37232cd5b2
4 changed files with 58 additions and 1 deletions

View File

@ -19,6 +19,10 @@ gem 'acts-as-taggable-on'
group :development do
gem 'better_errors', path: 'lib/better_errors'
gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler'
if ENV['PRY']
gem 'pry'
gem 'pry-nav'
end
end
# Optional gem for LDAP authentication

View File

@ -6,6 +6,13 @@ alias
name firstname+lastname login
nickname xxx login
realname xxx firstname+lastname
User model经过修改已经完全集成了user_extensions的功能
例如
user.gender=1
user.save
user_extensions字段会自动保存
不必要每次user.user_extensions.xxx以及判断是否为空
================================================================================
app/models/setting.rb :165
# fixed domain url in development. tantantan's bug

View File

@ -199,6 +199,53 @@ class User < Principal
end
}
# ======================================================================
# 集中处理 User 扩展表为空的问题
validate :valid_user_extensions
before_save :save_user_extensions
def extensions
self.user_extensions ||= self.create_user_extensions
end
def respond_to?(m, include_private = false)
flag = extensions.respond_to? m.to_sym
if flag
flag
else
super
end
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.extensions.__send__ m.to_sym, *args
end
__send__ m.to_sym, *args, &block
else
super
end
end
def valid_user_extensions
if !self.extensions.valid?
self.extensions.errors.messages.each do |key, values|
values.each do |value|
self.errors.add key, value
end
end
end
end
def save_user_extensions
self.extensions.save
end
# 集中处理 User 扩展表为空的问题 < end
# ======================================================================
#选择项目成员时显示的用户信息文字
def userInfo
info=self.nickname + ' (' + self.realname + ')';

View File

@ -34,7 +34,6 @@
<h3 style="padding-left: 10px;"><%= l(:label_my_account) %></h3>
<%= error_messages_for 'user' %>
<%= error_messages_for 'se' %>
<fieldset class="box" style="margin:10px;">
<fieldset class="collapsible collapsed" style="width:800px;margin-left: 10px;">