Skip to content

Instantly share code, notes, and snippets.

@unakatsuo
Created August 23, 2011 18:05
Show Gist options
  • Save unakatsuo/1166020 to your computer and use it in GitHub Desktop.
Save unakatsuo/1166020 to your computer and use it in GitHub Desktop.
Rails session localization tips.
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def local_session
session[params[:controller].to_s] ||= {}
end
def reset_local_session
session.delete(params[:controller].to_s)
end
end
# This tip allows to use same session key name in different controllers.
# Also provides clear keys only for the controller name scope.
#
#class Page1 < ApplicationController
# def enter
# local_session[:params]=params
# redirect_to :action=>:confirm
# end
#
# def confirm
# if request.post?
# # save to file or DB
# reset_local_session
# redirect_to :action=>:finish
# return
# end
# end
#
# def finish
# end
#end
#
#class Page2 < ApplicationController
# def enter
# local_session[:params]=params
# redirect_to :action=>:confirm
# end
#
# def confirm
# if request.post?
# # save to file or DB
# reset_local_session
# redirect_to :action=>:finish
# return
# end
# end
#
# def finish
# end
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment