We cover:

  • Representational State Transfer (REST)
  • Defining how requests are routed to controllers
  • Selecting a data representation
  • Testing routes
  • The controller environment
  • Rendering and redirecting
  • Sessions, flash, and callbacks

Chapter 20
Action Dispatch and Action Controller

Action Pack lies at the heart of Rails applications. It consists of three Ruby modules: ActionDispatch, ActionController, and ActionView. Action Dispatch routes requests to controllers. Action Controller converts requests into responses. Action View is used by Action Controller to format those responses.

As a concrete example, in the Depot application, we routed the root of the site (/) to the index method of the StoreController. At the completion of that method, the template in app/views/store/index.html.erb was rendered. Each of these activities was orchestrated by modules in the Action Pack component.

Working together, these three submodules provide support for processing incoming requests and generating outgoing responses. In this chapter, we’ll look at both Action Dispatch and Action Controller. In the next chapter, we will cover Action View.

When we looked at Active Record, we saw it could be used as a freestanding library; we can use Active Record as part of a nonweb Ruby application. Action Pack is different. Although it is possible to use it directly as a framework, you probably won’t. Instead, you’ll take advantage of the tight integration offered by Rails. Components such as Action Controller, Action View, and Active Record handle the processing of requests, and the Rails environment knits them together into a coherent (and easy-to-use) whole. For that reason, we’ll describe Action Controller in the context of Rails. Let’s start by looking at how Rails applications handle requests. We’ll then dive down into the details of routing and URL handling. We’ll continue by looking at how you write code in a controller. Finally, we will cover sessions, flash, and callbacks.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.2.78