-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#... | |
module MyApp | |
class Application < Rails::Application | |
#... | |
config.after_initialize do | |
require 'session_patch' | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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