dmarucco
dmarucco

Reputation: 590

Ruby Frameworks - Request Entry Point

I'm learning ruby and looking at his frameworks. One things that i can't understand is how frameworks handles requests in ruby world. Digging deeper I found that there's a middleware called Rack that does the job.

So my questions are:

Thanks in advance.

Upvotes: 3

Views: 766

Answers (1)

roydq
roydq

Reputation: 312

From the rack specification:

A Rack application is an Ruby object (not a class) that responds to call. It takes exactly one argument, the environment and returns an Array of exactly three values: The status, the headers, and the body.

In pratice, the common way that a rack application is started is defined in a config.ru file. If you look in the base directory of a rails app you will see it. In rails, it includes config/environment.rb, which includes config/application.rb, which includes boot.rb, which includes gems and whatnot. From that point the framework starts to do its thing.

The general idea with rails is that a dispatcher takes any request and decides what needs to be done with it. The dispatcher can be seen as an equivalent to the index.php you mentioned.

How the config.ru file gets accessed (or how the rack app is started) is dependent on the way your application is deployed. Phusion Passenger, a popular module for apache and nginx, will look for config.ru in the root directory of any application you have added to the server config file.

It really comes down to the deployment option. Ruby apps can be run via apache/nginx modules, directly via web servers written in ruby, and via CGI.

Here is a description of the different ways web apps are deployed, from the passenger docs

Upvotes: 4

Related Questions