Streamlining the curriculum.
Goal of this lesson is to understand what middlewares in Rack are good for.
Rack
Start with these articles:
- Rails on Rack Show archive.org snapshot
- Introduction to Rack Middleware
- Short Screencast to a sample Middleware Show archive.org snapshot
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
inApplicationController
?
Rails middleware
Now look at the middleware stack of a freshly installed Rails application Show archive.org snapshot . 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 Show archive.org snapshot and understand how it does this (hint: it’s a middleware!).
Excercises
- Write a Middleware that makes a Rails application respond to
GET /hello
when added to the middleware stack. The path would simply printHI WORLD
with atext/plain
content type. - Write a Middleware that prints
OUCH
to the screen whenever the Rails application raises an unhandled error.
Posted by Henning Koch to makandra Curriculum (2015-08-04 18:36)