Rack-based Session Stores on Rails
Posted by Christopher Rigor on December 22, 2008
Filed Under Ruby on Rails, Web Development
Rails edge is now using Rack-based session stores. That means you can access the same session on any Rack applications. Read about it on the Rails blog.
Nothing changes though on how you use sessions on Rails. On your Rails app, you’ll have something like
session[:user] = some_user_id
Let’s see how we can access the same session on a Rack application. You can read about Rack here.
Rack handles session using Rack::Session::Cookie. Create a file config.ru
use Rack::Session::Cookie, :key => '_railssession_session', :domain => 'railssession.labs.admoolabs.com'
run Proc.new {|env| [200, {"Content-Type" => "text/html"}, "Rack session 'user' has a value of #{env['rack.session'][:user] || 'nil'}."]}
The key should be the same key that you used on config/environment.rb on your Rails app.
Check out the demo. Set session[:user] on the Rails app, then view the session on the Rack app.
Comments
-
deadbeat millionaire bonus
-
Bala Paranj