Skip to content

Instantly share code, notes, and snippets.

@AMEE
Created December 22, 2011 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AMEE/1510847 to your computer and use it in GitHub Desktop.
Save AMEE/1510847 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
@schougaard
Copy link

Put session_patch.rb in lib/ or similar

@amolpujari
Copy link

this wont require any more, still keeping it can throw error of cannot modify flash, specially in case of activeadmin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment