From 83f62a069e6723c994365855bd9509d5b1a218bc Mon Sep 17 00:00:00 2001 From: Rafael Magana Date: Tue, 22 May 2012 21:33:49 -0500 Subject: use ApplicationName::Application instead of ActionController::Dispatcher.new since Dispatcher class no longer exists --- guides/source/rails_on_rack.textile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'guides/source') diff --git a/guides/source/rails_on_rack.textile b/guides/source/rails_on_rack.textile index d8910cf1d0..0080982b67 100644 --- a/guides/source/rails_on_rack.textile +++ b/guides/source/rails_on_rack.textile @@ -23,7 +23,7 @@ h3. Rails on Rack h4. Rails Application's Rack Object -ActionController::Dispatcher.new is the primary Rack application object of a Rails application. Any Rack compliant web server should be using +ActionController::Dispatcher.new+ object to serve a Rails application. +ApplicationName::Application 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+ @@ -36,7 +36,7 @@ app = Rack::Builder.new { use Rails::Rack::LogTailer unless options[:detach] use Rails::Rack::Debugger if options[:debugger] use ActionDispatch::Static - run ActionController::Dispatcher.new + run ApplicationName::Application }.to_app @@ -57,7 +57,7 @@ require "config/environment" use Rails::Rack::LogTailer use ActionDispatch::Static -run ActionController::Dispatcher.new +run ApplicationName::Application And start the server: @@ -111,7 +111,7 @@ use ActionDispatch::Head use Rack::ConditionalGet use Rack::ETag use ActionDispatch::BestStandardsSupport -run Blog::Application.routes +run ApplicationName::Application.routes Purpose of each of this middlewares is explained in the "Internal Middlewares":#internal-middleware-stack section. @@ -172,7 +172,7 @@ use ActionDispatch::Static use # use Rack::Runtime ... -run Myapp::Application.routes +run Blog::Application.routes h4. Internal Middleware Stack @@ -264,7 +264,7 @@ config.middleware.clear # config.ru use MyOwnStackFromScratch -run ActionController::Dispatcher.new +run ApplicationName::Application h3. Resources -- cgit v1.2.3 From 56ad6ca3ffe739e9ef445f39bf7c6ff3111ca42b Mon Sep 17 00:00:00 2001 From: Rafael Magana Date: Tue, 22 May 2012 22:02:20 -0500 Subject: update loaded middlewares and use of Rack::Server instead of Rack::Builder --- guides/source/rails_on_rack.textile | 46 ++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'guides/source') diff --git a/guides/source/rails_on_rack.textile b/guides/source/rails_on_rack.textile index 0080982b67..b85b09241e 100644 --- a/guides/source/rails_on_rack.textile +++ b/guides/source/rails_on_rack.textile @@ -27,25 +27,45 @@ h4. Rails Application's Rack Object h4. +rails server+ -rails server does the basic job of creating a +Rack::Builder+ object and starting the webserver. This is Rails' equivalent of Rack's +rackup+ script. +rails server does the basic job of creating a +Rack::Server+ object and starting the webserver. -Here's how +rails server+ creates an instance of +Rack::Builder+ +Here's how +rails server+ creates an instance of +Rack::Server+ -app = Rack::Builder.new { - use Rails::Rack::LogTailer unless options[:detach] - use Rails::Rack::Debugger if options[:debugger] - use ActionDispatch::Static - run ApplicationName::Application -}.to_app +Rails::Server.new.tap { |server| + require APP_PATH + Dir.chdir(Rails.application.root) + server.start +} -Middlewares used in the code above are primarily useful only in the development environment. The following table explains their usage: +The +Rails::Server+ inherits from +Rack::Server+ and calls the +Rack::Server#start+ method this way: + + +class Server < ::Rack::Server + def start + ... + super + end +end + + +Here's how it loads the middlewares: + + +def middleware + middlewares = [] + middlewares << [Rails::Rack::Debugger] if options[:debugger] + middlewares << [::Rack::ContentLength] + Hash.new(middlewares) +end + + ++Rails::Rack::Debugger+ is primarily useful only in the development environment. The following table explains the usage of the loaded middlewares: |_.Middleware|_.Purpose| -|+Rails::Rack::LogTailer+|Appends log file output to console| -|+ActionDispatch::Static+|Serves static files inside +Rails.root/public+ directory| |+Rails::Rack::Debugger+|Starts Debugger| +|+Rack::ContentLength+|Counts the number of bytes in the response and set the HTTP Content-Length header| h4. +rackup+ @@ -55,8 +75,8 @@ To use +rackup+ instead of Rails' +rails server+, you can put the following insi # Rails.root/config.ru require "config/environment" -use Rails::Rack::LogTailer -use ActionDispatch::Static +use Rack::Debugger +use Rack::ContentLength run ApplicationName::Application -- cgit v1.2.3 From 7cabb57f6b9ceaef48a7500e2333cddb69c90de0 Mon Sep 17 00:00:00 2001 From: Rafael Magana Date: Tue, 22 May 2012 22:09:43 -0500 Subject: use ActionDispatch::MiddlewareStack instead of ActionController::MiddlewareStack --- guides/source/rails_on_rack.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides/source') diff --git a/guides/source/rails_on_rack.textile b/guides/source/rails_on_rack.textile index b85b09241e..3a7c392508 100644 --- a/guides/source/rails_on_rack.textile +++ b/guides/source/rails_on_rack.textile @@ -92,11 +92,11 @@ To find out more about different +rackup+ options: $ rackup --help -h3. Action Controller Middleware Stack +h3. Action Dispatcher Middleware Stack -Many of Action Controller's internal components are implemented as Rack middlewares. +ActionController::Dispatcher+ uses +ActionController::MiddlewareStack+ to combine various internal and external middlewares to form a complete Rails Rack application. +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: +ActionController::MiddlewareStack+ is Rails' equivalent of +Rack::Builder+, but built for better flexibility and more features to meet Rails' requirements. +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 -- cgit v1.2.3