【发布时间】:2014-10-18 18:51:16
【问题描述】:
我在我的用户模型上启用了乐观锁定,以处理我的代码库各个部分中可能出现的冲突。但是,我遇到了意想不到的冲突,我不知道如何处理它,因为我不知道是什么原因造成的。
我正在使用 Devise gem 进行身份验证,并且我正在使用 before_logout 方法来重置安全令牌...
class SessionsController < Devise::SessionsController
after_filter :after_login, :only => :create
before_filter :before_logout, :only => :destroy
def after_login
# logic to set the security token
end
def before_logout
current_user.update(security_token: nil) # <--"Attempted to update a stale object: User"
end
end
我是 Rails 的新手(才几周),所以我真的不知道在我的代码中还有什么地方可以查看,也不知道为什么这段代码会抛出异常。非常感谢任何建议或想法。
提前感谢您的智慧!
【问题讨论】:
标签: ruby-on-rails ruby activerecord devise