O'Reilly logo

Ruby on Rails® Bible by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Controller: In Depth

In this chapter, you will learn about the controller layer of the MVC framework implemented in Rails applications. The controller layer of an MVC application is responsible for figuring out what to do with external input. The controller layer interprets user input and responds to user requests by communicating with the model layer, and rendering views using the view layer. You can think of the controller as the conductor of the application; it determines which views to show based on the input received.

The controller layer should be the only layer of your application that knows the client is actually a Web browser. All interaction with the Web server and knowledge of such interaction should be confined to methods in your controller classes. This layer should not contain a great deal of your business logic; the business logic should be contained within your model layer. Theoretically, you could rewrite the controller layer to adapt the application to a different platform, such as a non-browser environment.

Rails implements the controller layer primarily using a component called ActionController. ActionController is joined with ActionView to make up the Action Pack component of Rails. Action Pack provides the functionality for processing incoming requests from the browser and for generating responses to the browser.

What is ActionController?

In Rails, your application's controller and view layers use the Action Pack components of Rails. Controllers are ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required