Book Image

Layered Design for Ruby on Rails Applications

By : Vladimir Dementyev
4.7 (3)
Book Image

Layered Design for Ruby on Rails Applications

4.7 (3)
By: Vladimir Dementyev

Overview of this book

Ruby on Rails is an open-source framework for building web applications from scratch while focusing on productivity, leveraging the power of the convention-over-configuration principle, and the well-defined model-view-controller pattern, assisting the developers in building useful features. However, this initial simplicity often leads to uncontrollable complexity turning the well-structured codebase into a hardly maintainable mess. This book aims to help you keep the code maintainable while working on a Rails application. You’ll start by exploring the framework capabilities and principles, allowing you to reap the full potential of Rails. Then, you’ll tackle many common design problems by discovering useful patterns and abstraction layers. By implementing abstraction and dividing the application into manageable modules, you’ll be able to concentrate on specific parts of the app development without getting overwhelmed by the entire codebase. This strategy also encourages code reuse, simplifying the process of adding new features and enhancing the application's capabilities. Additionally, you’ll explore further steps in scaling Rails codebase, such as service extractions. By the end of this book, you’ll be a code design specialist with a deep understanding of the Rails framework principles.
Table of Contents (20 chapters)
1
Part 1: Exploring Rails and Its Abstractions
7
Part 2: Extracting Layers from Models
11
Part 3: Essential Layers for Rails Applications
17
Index
18
Gems and Patterns

Active Models and Records

In this chapter, we will dig deeper into the model layer of web applications and how it is implemented in Rails. The model layer, in a broad sense, is where the actual business logic of the application lives. If the database is the heart of a web application, the model is its life-blood system. Thus, it requires your careful attention.

We will learn about the components Rails provides to build the model layer. First, we’ll take a quick look at a basic Active Record model and examine its responsibilities, from persistence to whatever you can imagine. Then, we’ll discuss the role of Active Model and how it could be useful on its own. Finally, we’ll talk about the phenomenon of God objects and how it relates to Active Record.

We will cover the following topics:

  • Active Record overview: persistence and beyond
  • Active Model: the hidden gem behind Active Record
  • Seeking God objects

This chapter aims to familiarize you...