Posted 17 days ago. Visible to the public.

Reading the Rails session hash from a Rack middleware

To read the Rails session from a Rack middleware, use env['rack.session']. It's an ActionDispatch::Request::Session object.

Copy
class MyMiddlware def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) session = env['rack.session'] Rails.logger.info("Value of session['foo'] is: " + session['foo'].inspect) [status, headers, body] end end

You may not be able to write to the session this way (I haven't tested this).

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Avatar
Henning Koch
Last edit:
17 days ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more