Skip to content
royw edited this page Aug 17, 2012 · 1 revision
Note:  This is a work in progress

Request flow

Describe how a request flows from rack to innate to ramaze to your controller and the reverse response flow.

URL Parsing

Describe how the given request URL is parsed and handled by the controller. Include accessing request and building response.

URL Format

The expected URLs look like

"http://address/controller/action.type/parameters".

The "address" is where the web application is residing and may include a port.

The "controller" part may be matched two ways: To the value given the "map" method in the controller, or from the name of the controller (using the controller naming convention).

The "action" is optional (defaults to "index") and invokes the method with the same name inside the controller.

The ".type" is optional (defaults to "html"), but if given then the "action" must be explicitly given too, and requests that the action return this type of data. The "provide" method is used to handle non-HTML requests and is responsible for converting any data to the requested content type.

The "parameters" are passed as variable arguments to the action method.

Whew! What a mouthful! I say a couple of examples are needed:

    http://localhost:7000
    # calls MainController.index()
    # expects HTML content
    # Explanation: convention maps the main controller to '/', the default action is "index", default content-type is HTML

    http://localhost:7000/index
    # same as above but explicitly calling the "index" action

    http://localhost:7000/index.html
    # same as previous but explicitly specifying the content-type

    http://localhost:7000/index.json
    # same as previous but specifying JSON content-type.

    http://localhost:7000/equipment/show
    # calls EquipmentController.show()
    # Explanation: Using convention, tries to find EquipmentController (by convention should be in controllers/equipment.rb)
    # or a controller with a "map 'equipment'" statement.  The action "show" is explicitly requested.

    http://localhost:7000/equipment/show.json/42
    # calls EquipmentController.show('42') and expects a "provide" block for content-type of 'json'.

    http://localhost:7000/equipment/show.json/42/towel/1
    # calls EquipmentController.show('42', 'towel', '1') and expects a "provide" block for content-type of 'json'.

Notice that the HTTP request method (GET, PUT, POST, DELETE) has no effect on routing. FYI, the request method is passed in the request's env hash: request.env["REQUEST_METHOD"].

Request Injection for tests

Describe using rack-test to inject requests into the rack flow.

Clone this wiki locally