aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/rails_on_rack.md
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2012-09-01 17:25:58 -0400
committerPrem Sichanugrist <s@sikac.hu>2012-09-17 15:54:22 -0400
commit872b7af337196febc516cb6218ae3d07f01a11a8 (patch)
treebc31fdc0803fff3aed26b6599cf2df7789055a41 /guides/source/rails_on_rack.md
parent7bc1ca351523949f6b4ce96018e95e61cbc7719e (diff)
downloadrails-872b7af337196febc516cb6218ae3d07f01a11a8.tar.gz
rails-872b7af337196febc516cb6218ae3d07f01a11a8.tar.bz2
rails-872b7af337196febc516cb6218ae3d07f01a11a8.zip
Convert heading tags and heading section
Diffstat (limited to 'guides/source/rails_on_rack.md')
-rw-r--r--guides/source/rails_on_rack.md41
1 files changed, 23 insertions, 18 deletions
diff --git a/guides/source/rails_on_rack.md b/guides/source/rails_on_rack.md
index 8ca896f358..d3a49cecd1 100644
--- a/guides/source/rails_on_rack.md
+++ b/guides/source/rails_on_rack.md
@@ -1,4 +1,5 @@
-h2. Rails on Rack
+Rails on Rack
+=============
This guide covers Rails integration with Rack and interfacing with other Rack components. By referring to this guide, you will be able to:
@@ -7,11 +8,12 @@ This guide covers Rails integration with Rack and interfacing with other Rack co
* Understand Action Pack's internal Middleware stack
* Define a custom Middleware stack
-endprologue.
+--------------------------------------------------------------------------------
WARNING: This guide assumes a working knowledge of Rack protocol and Rack concepts such as middlewares, url maps and +Rack::Builder+.
-h3. Introduction to Rack
+Introduction to Rack
+--------------------
bq. Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.
@@ -19,13 +21,14 @@ bq. Rack provides a minimal, modular and adaptable interface for developing web
Explaining Rack is not really in the scope of this guide. In case you are not familiar with Rack's basics, you should check out the "Resources":#resources section below.
-h3. Rails on Rack
+Rails on Rack
+-------------
-h4. Rails Application's Rack Object
+### Rails Application's Rack Object
<tt>ApplicationName::Application</tt> is the primary Rack application object of a Rails application. Any Rack compliant web server should be using +ApplicationName::Application+ object to serve a Rails application.
-h4. +rails server+
+### +rails server+
<tt>rails server</tt> does the basic job of creating a +Rack::Server+ object and starting the webserver.
@@ -67,7 +70,7 @@ end
|+Rails::Rack::Debugger+|Starts Debugger|
|+Rack::ContentLength+|Counts the number of bytes in the response and set the HTTP Content-Length header|
-h4. +rackup+
+### +rackup+
To use +rackup+ instead of Rails' +rails server+, you can put the following inside +config.ru+ of your Rails application's root directory:
@@ -92,13 +95,14 @@ To find out more about different +rackup+ options:
$ rackup --help
```
-h3. Action Dispatcher Middleware Stack
+Action Dispatcher Middleware Stack
+----------------------------------
Many of Action Dispatchers's internal components are implemented as Rack middlewares. +Rails::Application+ uses +ActionDispatch::MiddlewareStack+ to combine various internal and external middlewares to form a complete Rails Rack application.
NOTE: +ActionDispatch::MiddlewareStack+ is Rails' equivalent of +Rack::Builder+, but built for better flexibility and more features to meet Rails' requirements.
-h4. Inspecting Middleware Stack
+### Inspecting Middleware Stack
Rails has a handy rake task for inspecting the middleware stack in use:
@@ -136,11 +140,11 @@ run ApplicationName::Application.routes
Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section.
-h4. Configuring Middleware Stack
+### Configuring Middleware Stack
Rails provides a simple configuration interface +config.middleware+ for adding, removing and modifying the middlewares in the middleware stack via +application.rb+ or the environment specific configuration file <tt>environments/&lt;environment&gt;.rb</tt>.
-h5. Adding a Middleware
+#### Adding a Middleware
You can add a new middleware to the middleware stack using any of the following methods:
@@ -161,7 +165,7 @@ config.middleware.use Rack::BounceFavicon
config.middleware.insert_after ActiveRecord::QueryCache, Lifo::Cache, :page_cache => false
```
-h5. Swapping a Middleware
+#### Swapping a Middleware
You can swap an existing middleware in the middleware stack using +config.middleware.swap+.
@@ -172,7 +176,7 @@ You can swap an existing middleware in the middleware stack using +config.middle
config.middleware.swap ActionDispatch::ShowExceptions, Lifo::ShowExceptions
```
-h5. Middleware Stack is an Enumerable
+#### Middleware Stack is an Enumerable
The middleware stack behaves just like a normal +Enumerable+. You can use any +Enumerable+ methods to manipulate or interrogate the stack. The middleware stack also implements some +Array+ methods including <tt>[]</tt>, +unshift+ and +delete+. Methods described in the section above are just convenience methods.
@@ -212,7 +216,7 @@ config.middleware.delete "ActionDispatch::BestStandardsSupport"
config.middleware.delete "Rack::MethodOverride"
```
-h4. Internal Middleware Stack
+### Internal Middleware Stack
Much of Action Controller's functionality is implemented as Middlewares. The following list explains the purpose of each of them:
@@ -284,7 +288,7 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
TIP: It's possible to use any of the above middlewares in your custom Rack stack.
-h4. Using Rack Builder
+### Using Rack Builder
The following shows how to replace use +Rack::Builder+ instead of the Rails supplied +MiddlewareStack+.
@@ -304,15 +308,16 @@ use MyOwnStackFromScratch
run ApplicationName::Application
```
-h3. Resources
+Resources
+---------
-h4. Learning Rack
+### Learning Rack
* "Official Rack Website":http://rack.github.com
* "Introducing Rack":http://chneukirchen.org/blog/archive/2007/02/introducing-rack.html
* "Ruby on Rack #1 - Hello Rack!":http://m.onkey.org/ruby-on-rack-1-hello-rack
* "Ruby on Rack #2 - The Builder":http://m.onkey.org/ruby-on-rack-2-the-builder
-h4. Understanding Middlewares
+### Understanding Middlewares
* "Railscast on Rack Middlewares":http://railscasts.com/episodes/151-rack-middleware