---
title: "Rails 5 ensures compatibility with Rack frameworks"
description:
  "Rails 5 introduces `each` method in ActionDispatch::Request::Session to
  ensure compatibility between Rails and other Rack frameworks."
canonical_url: "https://www.bigbinary.com/blog/rails-5-ensures-compatibility-between-action-dispatch-session-and-rack-session"
markdown_url: "https://www.bigbinary.com/blog/rails-5-ensures-compatibility-between-action-dispatch-session-and-rack-session.md"
---

# Rails 5 ensures compatibility with Rack frameworks

Rails 5 introduces `each` method in ActionDispatch::Request::Session to ensure
compatibility between Rails and other Rack frameworks.

- Author: Mohit Natoo
- Published: June 30, 2016
- Categories: Rails 5, Rails

Before Rails 5,
[there were errors in running integration tests](https://github.com/rails/rails/issues/15843)
when a Rack framework like `Sinatra`, `Grape` etc. were mounted within Rails
with a motive of using its session.

Problems were reported at many places including
[github gists](https://gist.github.com/toolmantim/9597022) and
[stackoverflow](http://stackoverflow.com/questions/22439361/rspec-testing-api-with-rack-protection)
regarding an error which was of the following form.

```plaintext

NoMethodError (undefined method `each' for #<ActionDispatch::Request::Session:0x7fb8dbe7f838 not yet loaded>): rack (1.5.2) lib/rack/session/abstract/id.rb:158:in `stringify_keys'
rack (1.5.2) lib/rack/session/abstract/id.rb:95:in `update' rack (1.5.2) lib/rack/session/abstract/id.rb:258:in `prepare_session'
rack (1.5.2) lib/rack/session/abstract/id.rb:224:in `context' rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'

```

As we can see, the error occurs due to absence of method `each` on an
`ActionDispatch::Request::Session` object.

In Rails 5, `each` method
[was introduced to ActionDispatch::Request::Session](https://github.com/rails/rails/pull/24820)
class making it compatible with Rack frameworks mounted in Rails and hence
avoiding the above mentioned errors in integration testing.

## Links

- [Human page](https://www.bigbinary.com/blog/rails-5-ensures-compatibility-between-action-dispatch-session-and-rack-session)
