我使用authlogic gem有一个非常简单的登录/注销代码。 有时候,我会得到" NoMethodError:未定义的方法`[] ='为零:NilClass"对于我的注销码 - 在user_session.destroy中。 我从来没有设法自己重现它,但它发生了......
get 'logout' do
user_session = UserSession.find
if user_session
user_session.destroy
return {status: 200, message: 'Success'}
else
return {status: 400, message: 'No session to destroy'}
end
end
回溯:
/home/admin/.rvm/gems/ruby-1.9.3-p392/gems/authlogic-3.3.0/lib/authlogic/session/session.rb:56:in
update_session' /home/admin/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:418:in
运行 _509239456491140030__after_destroy_ 1525954531983478469 _callbacks' /home/admin/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in__run_callback' /home/admin/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in
_ run_after_destroy_callbacks' /home/admin/.rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:inrun_callbacks' /home/admin/.rvm/gems/ruby-1.9.3-p392/gems/authlogic-3.3.0/lib/authlogic/session/callbacks.rb:88:in
after_destroy' /home/admin/.rvm/gems/ruby-1.9.3-p392/gems/authlogic-3.3.0/lib/authlogic/session/existence.rb:50:in`stroy'
UPDATE - 这是我的UserSession类实现:
class UserSession < Authlogic::Session::Base
allow_http_basic_auth false
def remember_me_for
14.days
end
def self.last_request_at_threshold
10.minutes
end
def perishable_token_valid_for
10.minutes
end
disable_magic_states(true)
end
请帮助:( 谢谢!