Posted about 3 years ago. Visible to the public.

Rack and Middlewares

Goal of this lesson is to understand what middlewares in Rack are good for.


Start with these articles:

You should be able to answer the following questions:

  • What is Rack?
  • How does Rack relate to Ruby on Rails?
  • What is Rack middleware?
  • What are some advantages of implementing functionality as a middleware as opposed to e.g. a before_filter in ApplicationController?

Rails middleware

Now look at the middleware stack of a freshly installed Rails application. For each middleware in the stack:

  • What does it do?
  • What would happen if we removed it from the stack?
  • Can you find the code that implements it?

Exception Notification

We are using the exception_notification gem to receive an e-mail whenever one of our apps raises an unhandled exception.

Look through the repo and understand how it does this (hint: it’s a middleware!).


  • Write a Middleware that makes a Rails application respond to GET /hello when added to the middleware stack. The path would simply print HI WORLD with a text/plain content type.
  • Write a Middleware that prints OUCH to the screen whenever the Rails application raises an unhandled error.

Owner of this card:

Henning Koch
Last edit:
about 1 year ago
by Michael Leimstädtner
Posted by Henning Koch to makandra Curriculum
This website uses cookies to improve usability and analyze traffic.
Accept or learn more