Accessing the "session key" cookie name from anywhere in Rails

cookies, ruby-on-rails, session

Solution

I found the solution. In Rails 2.3.2 at least the session key in set in `config/initializers/session_store.rb` like this:

ActionController::Base.session = {
  :key         => '_myapp_session',
  :secret      => '[...]'
}

And you can read the value like this:

ActionController::Base.session_options[:key]

From `Base.session` to `Base.session_options` automagically, doesn't make much sense, and it caused me a big headache... lol

Problem

We are building a plugin for Rails to be used within iframe Facebook applications, and at one point we need to check if Rail's session id cookie as been set or not. By default, this cookie is named _myprojectname_session, what we need to find out is the actual name of the cookie itself. So if it's not set, we can do some redirects to make sure the cookies are set. How do we access the damn name of the cookie from anywhere? Or at least from within a controller?

Original source