Caching of roles

6 views
Skip to first unread message

vitalyny

unread,
May 4, 2010, 4:33:20 PM5/4/10
to acl9-discuss
Hey,

I implemented authentication with Authlogic and authorization with
Acl9. Now I'm trying to avoid multiple hits to database to check if
user is admin by keeping this in the session.

What I thought is that this code should work:

class ApplicationController < ActionController::Base
...
helper_method :current_user_session, :current_user, :is_admin
...

private
def is_admin
return current_user_session[:is_admin] if defined?
(current_user_session[:is_admin])
current_user_session[:is_admin] = current_user.has_role?
(:admin)
end

So basically on a first call to is_admin helper method, it should add
a boolean value to session[:is_admin] and then for any other calls,
take it from the session. But I receive this error:

undefined method `[]=' for #<UserSession:
{:unauthorized_record=>"<protected>"}>

And I stuck here. What am I doing wrong?

oleg dashevskii

unread,
May 4, 2010, 10:17:09 PM5/4/10
to acl9-d...@googlegroups.com
I think you should use session[:foobar], not current_user_session[:foobar]

2010/5/5 vitalyny <vitaly....@gmail.com>:
--
Олег.

vitalyny

unread,
Jun 24, 2010, 4:09:44 PM6/24/10
to acl9-discuss
That is a great advice! Thank you, Oleg.

On May 4, 10:17 pm, oleg dashevskii <olegdashevs...@gmail.com> wrote:
> I think you should use session[:foobar], not current_user_session[:foobar]
>
> 2010/5/5 vitalyny <vitaly.mura...@gmail.com>:

Sharad Jain

unread,
Jun 24, 2010, 4:12:34 PM6/24/10
to acl9-d...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages