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 3. Using Active Record

Rails applications implement the model-view-controller (MVC) design pattern. The model layer of an MVC application implements the application's business logic and encapsulates the application's data. This is often the most significant part of an application. It is this layer that should contain the core of your functionality. The view and controller layers could be replaced to re-implement your application in another environment, such as when converting a desktop application to a Web application; however, the model layer can ideally remain intact across these different operating environments.

Rails implements the model layer primarily using a component called Active Record. Active Record provides a powerful abstraction layer and is often referred to as elegant because of its use of the following techniques:

  • Convention over configuration: If you follow Active Record's conventions, you'll save yourself from having to write many lines of configuration code. Active Record is able to automatically discover the details of your database schema and provide you with simple functionality for accessing and managing your data.

  • Metaprogramming: Using metaprogramming, Active Record dynamically adds features to your model classes, saving you from having to write common code over and over again. For example, Active Record adds attributes to your model objects for every column in your database tables.

  • Domain-specific language: Rails implements a domain-specific language ...

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