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 ...
Get Ruby on Rails® Bible now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.