Skip the memoization

0 views
Skip to first unread message

Jared Fine

unread,
Nov 18, 2009, 2:30:51 PM11/18/09
to Authlogic
Figured I would share since I just got bit by this and took a little
while to figure out. The jist is don't use memoization on your session
models for authlogic. What happens is that memoize freezes the object
thus resulting in frozen object errors when you try to do things like
session.destroy.

GOOD:
class ApplicationController < ActionController::Base
...
private
def current_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = Session.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_session.try(:user)
end
...
end

NO GOOD:
class ApplicationController < ActionController::Base
...
extend ActiveSupport::Memoizable
private
def current_session
@current_user_session = Session.find
end
memoize :current_session
def current_user
@current_user = current_session.try(:user)
end
memoize :current_user
...
end

Kris Leech

unread,
Nov 19, 2009, 5:11:16 AM11/19/09
to auth...@googlegroups.com
This is a good tip it might be worth putting in the documentations
somewhere maybe under 'troubleshooting'...
> --
>
> You received this message because you are subscribed to the Google Groups "Authlogic" group.
> To post to this group, send email to auth...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/authlogic?hl=en.
>
>
>
>

Reply all
Reply to author
Forward
0 new messages