Thinking in components
The problem we’re trying to solve here—increasing the maintainability of the view layer—is not new. In the last decade, one design paradigm became prevalent: breaking down views into isolated, self-contained components. Every logical piece of UI must be backed by a component in your code base. Think in components, not templates.
This approach proved to be efficient in the world of frontend development. Modern libraries such as React, Vue, and Svelte all drive the component-based architecture.
How can we use this idea in Rails? Let’s try to build some view components!
Turning partials and helpers into components
Let’s consider what we need to turn partials and helpers into components. Components are isolated and self-contained. Thus, we need to keep all the logic related to a UI element in a single place. Isolation also means that we shouldn’t have access to a global state (for example, a controller’...