#设置
def setting
@user_setting = User.new
end
def setting_commit @user_setting = User.new(params[:user])
#安全校验注意
if @user_setting.nick_name && @user.nick_name != @user_setting.nick_name
if [email protected]_attributes(:nick_name=> @user_setting.nick_name)
logger.error("Err, setting update_attributes nick_name failed. userid:#{@user.id}")
return render(:action =>"setting")
end
end
if @user.contact_me != @user_setting.contact_me if [email protected]_attributes(:contact_me=>@user_setting.contact_me) logger.error("Err, setting update_attributes contact_me failed. userid:#{@user.id}") return render(:action =>"setting") end end
日志打出来是
Started POST "/user_index/setting_commit" for 192.168.56.1 at 2012-09-19 09:34:27 +0800
Processing by UserIndexController#setting_commit as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"S2SaDwM5IUd7+eAurpq+qAJi/uY3UHcvHjz+oCSlWvc=", "user"=>{"nick_name"=>"adddd", "contact_me"=>""}, "commit"=>"æ交"}
DEPRECATION WARNING: Calling set_primary_key is deprecated. Please use self.primary_key = 'the_name'
instead. (called from class:User at /home/lindp/Programmer/GitHub/jzns/jzns/app/models/user.rb:5)
User Load (0.3ms) SELECT users
.* FROM users
WHERE users
.id
= 2 LIMIT 1
(0.2ms) BEGIN
User Exists (0.5ms) SELECT 1 FROM users
WHERE (users
.nick_name
= BINARY 'adddd' AND users
.id
!= 2) LIMIT 1
(0.2ms) ROLLBACK
Err, setting update_attributes nick_name failed. userid:2
为什么 ROLLBACK 了??User Exists 这个原因有点看不懂,SELECT 1,这不肯定有值吗??