Ruby on Rails View Components with Trailblazer Cells
JavaScript is now more composable than ever, and it feels it won’t change for a long time as it’s one of the most efficient ways of creating websites and web apps now. But how do Ruby on Rails and View Components cooperate with each other? Is it possible to include component-based structure within RoR applications? With Trailblazer Cells, it is.

In recent times view components became a really popular web design pattern. View component is standalone part of view, which can be used at many views.
Most common JavaScript frontend frameworks like React, Ember or Angular use view components pattern. Even last hot topic in web world "Web Components" is just implementation of view components.
Ok, but it’s all about JavaScript world. What if we want to stay in Rails world? Can we use view components in RoR app? Yes, We can! We can do it with Trailblazer Cells.
On the first page of Cells documentation we read:
A cell is an object that represent a fragment of your UI. The scope of that fragment is up to you: it can embrace an entire page, a single comment container in a thread or just an avatar image link.
I could just list adventages of cells, but you can find them in the documentation. I would like to show simple example of cells’ usage. I hope it will show you benefits of view components in rails app.
The example is a simple app with CRUD actions for below database.

we
Let’s start by creating the app with scaffolds.
rails new cells-appcd cells-apprails g scaffold company name:string city:stringrails g scaffold department name:string company:referencesrails g scaffold employee first_name:string last_name:string department:referencesrake db:create db:migrateadd
root to: ‘companies#index’toconfig/routes.rb
We’ve created base app with scaffolds for company, department and employee. Now we can configure cells’:
Add to gemfile:
gem "trailblazer-cells"gem "cells-erb"gem "cells-rails"
Run
bundle installRun
mkdir app/cells
So, finally we can go to most interesting part – cells implementation. If we list the app/views we will see that we already have a lot of views:

We will use code from these views in our cells.
We will create cells for each type of view:
IndexCellShowCellNewCellEditCell
And some view components cells:
TableCellTitleCellFormCellNoticeCell
We will replace each template with cell. Completed project you can find on GitHub. Here I will just show two examples of cells: TableCell and IndexCell.
TableCell
Firstly, we need to create files structure. TableCell is built from one ruby file and four erb(html) files. Our cells’ directory should look like below.

table_cell.rb is the core of our cell, it contains all helpful methods.
table_cell.rb
tsx
The main view part of TableCell is show.erb, it will be rendered while we will use the cell. It contains table tag and renders header.erb and body.erb views.
table/show.erb
tsx
In header.erb we put thead tag and th tag for each attribute provided to cell.
table/header.erb
tsx
In body.erb we render table row for each item provided to cell.
table/body.erb
tsx
row.erb creates td tag for each attribute of the item.
table/row.erb
tsx
IndexCell
At first we need to add abstract PageCell with html layout, the main job of layout is including javascript and stylesheets assets. Each view needs to load the layout, so views cells will inherit from the PageCell. We have to create app/cells/page_cell.rb and app/cells/page/layout.erb files.
page_cell.erb
tsx
page/layout.erb
tsx
Let’s speed up. I’ve already created TitleCell and NoticeCell. We need them for IndexCell. IndexCell displays all of needed components on index page.
index_cell.erb
tsx
index/show.erb
tsx
Implementation of others cells you can see at the repository. So, we have all cells ready. Let’s use them.
companies_controller.rb
tsx
departments_controller.rb
tsx
employees_controller.rb
tsx
As you can see we have used the same cells for all controllers. That is the power of cells. Now If you want to change title header size for all pages, you have to just change one file, the TitleCell:
tsx
That’s all. The change at one file is propagated to all views. How cool is that? And that is the sense of cells.
Of course, cells have more advantages, but I had only one goal in this article. I wanted to show you that with cells you can create flexible and reusable views at rails. I hope that now you can see it.
Let’s Create a Great Website Together
We'll shape your web platform the way you win it!
More posts in this category

October 28, 2025 • 8 min read
READ MOREHydrogen or Next.js for Shopify in 2026 - Which Should Your Business Choose (and When)?
Choosing between Shopify Hydrogen and Next.js is a strategic business decision. Your choice defines speed to market, long-term flexibility, cost predictability, and even your brand’s ability to innovate.

October 24, 2025 • 14 min read
READ MOREBest WordPress Alternatives in 2026: Which CMS Is Right for You?
WordPress continues to dominate the CMS landscape, powering around 43.3% of all websites and about 60.7% of those using a CMS. However, today’s web ecosystem has evolved significantly, offering a wide range of platforms tailored to different needs, from marketing and ecommerce to enterprise and developer-focused projects.

October 21, 2025 • 7 min read
READ MOREWhy Is Your Website's Search Costing You Sales? How Algolia + Next.js Can Turn Queries into Revenue
Every search query is a customer literally telling you what they want. The question is: are you listening?
