What is Rack and how does Rails relate to it?
Answer
Rack is a minimal, modular Ruby web server interface specification. A Rack application is any Ruby object that responds to call(env) and returns a 3-element array: [status, headers, body]. Rails is a Rack application. The Rack middleware stack is a chain of Rack apps where each passes the request to the next. Run rails middleware to see the full stack. Each middleware layer handles a cross-cutting concern: sessions, logging, CSRF protection, asset serving, request tracing. You can add custom middleware: config.middleware.use MyMiddleware. This architecture allows sharing middleware between Rails, Sinatra, and any Rack-compatible framework.
Previous
How does Rails handle database connection pooling?
Next
What is query optimization with explain in Rails?
More Ruby on Rails Questions
View all →- Advanced What is metaprogramming in Ruby/Rails and give examples?
- Advanced What is the difference between include, extend, and prepend in Ruby?
- Advanced How does Rails handle database connection pooling?
- Advanced What is query optimization with explain in Rails?
- Advanced What are Rails engines and how are they used?