Hello -
I'm trying to have an account information and link bar at the top of the screen, i.e:
chris@example.com | My Profile | Logout
This bar should be up there even when the user is on a cached page (the app I'm working on has a lot of database-intensive screens, which luckily are well-suited to page caching). So, I set up a before filter in the application controller, like so:
before_filter :set_user_info_cookie private def set_user_info_cookie cookies[:user_info] = { :value => current_user.email, :expires => 1.hour.from_now } if current_user cookies.delete :user_info unless current_user end
(I'm using Authlogic for authentication)
Then I use jQuery to look for the "user_info" cookie - if it exists, it assumes the user is logged in and puts the email address and whatnot at the top of the screen. This is the only thing the cookie is used for, so security's not an issue (I don't think) and it's left in clear text.
There are two problems with my setup:
#1: "cookies.delete :user_info unless current_user" doesn't work. In fact, I can't figure out how to destroy that cookie at all. When I use the debugger, and then call cookies.delete [:user_info], I get the following array with two strings:
["user_credentials=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", "user_info=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"]
If I look at the cookies hash after that, it looks exactly the same as it did before I tried to delete the user_info cookie. Looking at the localhost cookies in Firefox, the user_info cookie is still there.
#2: I've just set up one controller specifically to serve static pages (which will also be page cached, but I want to use rails to make sure their layout matches the rest of the site). The controller actions are empty, and the views are still very simple, but whenever I try to access one of the static pages I get the following error, stemming from my set_user_info_cookie method: