On my site, I have a series of protected tabs and a series of public
tabs. Depending on the level of authentication, the tabs are viewable
to specific groups. I’ve encountered an old issue and I feel it’s time
to correct this problem. I’ve put it off for sometime now, and while
that’s not the best thing to do, I had a simple workaround in place.
The issue starts in the application controller through these lines here:
def get_user_tabs
if logged_in? && User.find(current_user).admin?
@tabs = Page.find_main
else
@tabs = Page.find_main_public
end
end
I use AuthenticatedSystem with activation for my site. If I login with
a specific admin group and check “remember me”, each subsequent visit
for the next week I’ll automatically be logged in.
However, the very first time I hit the website, I’ll receive the
following error:
NoMethodError (undefined method `refresh_token’ for #User:0x5ffe238)
The refresh_token in AuthenticatedSystem usually corresponds to the
remember_me token setting. I believe what’s happening is that the token
isn’t being refreshed until after the second page click on the site
occurs. Therefore, it will error out as per above.
I’ve gotten around this issue by doing the following rescue:
def get_user_tabs
begin
if logged_in? && User.find(current_user).admin?
@tabs = Page.find_main
else
@tabs = Page.find_main_public
end
rescue
logger.error(“undefined method `refresh_token”)
@tabs = Page.find_main_public
end
end
However, as you can see, I should not have to place a rescue in and the
corrupted data should not be allowed to reach as far as the rescue,
IMHO. I’ve searched many areas in AuthenticatedSystem from issues, to
wiki, etc. but can’t seem to pinpoint where this issue might be stemming
from. Perhaps it’s as simple as how I find the current user?
Any help on this matter would be appreciated.
Thanks.