I’ve had a few requests on how to access the session from Rack and Rails Metal. In the Rack environment that is passed to the call method, the session is stored at the ‘rack.session’ index. You can use this to both read from and write to the session. Here are some examples:
1
2
| session = env['rack.session']
User.find_by_id(session["user_id"]) |
1
2
| session = env['rack.session']
session["user_id"] = 1 |
rack, Rails, Rails Metal, sessions