Skip to content

Instantly share code, notes, and snippets.

@kidpollo
Forked from AMEE/application.rb
Created August 23, 2012 21:48
Show Gist options
  • Save kidpollo/3442335 to your computer and use it in GitHub Desktop.
Save kidpollo/3442335 to your computer and use it in GitHub Desktop.
Make Rails 3.1 use symbols in sessions so it can share Rails 2 sessions.
#...
module MyApp
class Application < Rails::Application
#...
config.after_initialize do
require 'session_patch'
end
end
end
# This patch makes Rails 3 use symbols as storage keys in sessions,
# as Rails 2 did.
module Rack
module Session
module Abstract
class SessionHash
def [](key)
load_for_read!
super(key.to_sym)
end
def has_key?(key)
load_for_read!
super(key.to_sym)
end
def []=(key, value)
load_for_write!
super(key.to_sym, value)
end
def delete(key)
load_for_write!
super(key.to_sym)
end
private
def stringify_keys(other)
hash = {}
other.each do |key, value|
hash[key.to_sym] = value
end
hash
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment