rails-session_jsonizer
rails-session_jsonizer is a simple library for Rails 3 and 4 to serialize session into JSON in the same format.
Work in progress
Requirement
- Rails 3.1 or later
Usage
In controller
session[:foo] = 'bar'
flash[:alert] = 'something went wrong'
Serialize
require 'session_jsonizer'
# dump
serializer = SessionJsonizer.new
json = serializer.dump(session)
json # => '{"foo":"bar", "flash":{"alert":"something went wrong"}, ...}'
# load
session = serializer.load(json)
Example: Store session into memcached as JSON using dalli
# config/initializers/session_store.rb
require 'action_dispatch/middleware/session/dalli_store'
Rails.application.config.session_store :dalli_store, serializer: SessionJsonizer.new, ...