Ruby on Rails Views & UI Management

πŸš€ Ruby on Rails Views & UI Management: The Complete Guide to Building Beautiful, Fast & Scalable Applications

β€œUsers don’t care how elegant your backend is if your UI frustrates them.”

Ruby on Rails is famous for rapid backend development, but many developers underestimate the importance of well-structured Views and UI architecture.

A poorly organized frontend becomes difficult to maintain, slow to render, and painful to scale.

This guide explains everything you need to know about Rails Views, UI architecture, optimization techniques, frontend integration, React, Hotwire, ViewComponents, and modern frontend approaches.

ChatGPT Image Jun 28, 2026, 09_11_05 PM

Let’s build Rails applications like professionals! πŸš€


πŸ“š Table of Contents

  1. Understanding Rails Views
  2. MVC & View Responsibility
  3. Principles of Clean UI Development
  4. Rails View Folder Structure
  5. ERB Best Practices
  6. Layouts & Partials
  7. Helpers
  8. View Components
  9. Presenters & Decorators
  10. Hotwire
  11. Turbo
  12. Stimulus JS
  13. Asset Management
  14. CSS Architecture
  15. UI Optimization Techniques
  16. Caching Views
  17. Lazy Loading
  18. Responsive Design
  19. Accessibility
  20. React + Rails
  21. Vue + Rails
  22. Angular + Rails
  23. Next.js + Rails API
  24. Inertia.js
  25. Hybrid Architecture
  26. Complete UI Folder Structure
  27. Performance Checklist
  28. Common Mistakes
  29. Best Architecture Recommendation

🎯 What is Rails View?

The View is responsible for presenting data to users.

Controller
     ↓
Model
     ↓
View

Never place business logic inside views.

Bad:

<%= @orders.select(&:paid?).sum(&:total) %>

Good:

# controller
@paid_total = Order.paid.sum(:total)
<%= @paid_total %>

πŸ— MVC Principle

Keep responsibilities separated.

Model

βœ… Business Logic

Controller

βœ… Flow

View

βœ… Presentation

Think of it like a restaurant.

Chef β†’ Model

Waiter β†’ Controller

Plate Decoration β†’ View


⭐ Golden Principles of UI Development

1️⃣ Thin Views

Views should only display data.

❌ Bad

<% if current_user.orders.where(status:"paid").count > 5 %>

βœ… Good

@premium_customer = current_user.premium?

2️⃣ Reusable Components

Instead of copying HTML:

Navbar
Footer
Cards
Buttons
Alerts

Create reusable components.


3️⃣ DRY Principle

Avoid repeating:

Bootstrap Cards
Buttons
Headers
Navigation
Forms

4️⃣ Single Responsibility

One partial = One purpose.

Example

_card.html.erb

_user.html.erb

_sidebar.html.erb

πŸ“ Ideal View Folder Structure

app/

 views/

   layouts/

   users/

   products/

   shared/

   dashboard/

   admin/

   errors/

Shared folder:

Navbar

Footer

Pagination

Flash Messages

Loader

Modal

🧩 Layouts

Application Layout

application.html.erb

Contains

Navbar

Footer

Flash

Yield

Javascript

CSS

Example

<body>

<%= render "shared/navbar" %>

<%= yield %>

<%= render "shared/footer" %>

</body>

🧱 Partials

Instead of

1000 lines HTML

Break into

_header

_sidebar

_product

_footer

Render

<%= render "product" %>

Collection rendering

<%= render @products %>

Rails automatically renders

_product.html.erb

🎨 Helpers

Never write formatting logic inside views.

Bad

<%= user.created_at.strftime(...) %>

Helper

module UsersHelper

def formatted_date(date)

date.strftime("%d %b %Y")

end

end

View

<%= formatted_date(user.created_at) %>

⚑ ViewComponent

One of the biggest improvements for Rails UI.

Instead of:

Partial

Helper

Javascript

CSS

Everything lives together.

ButtonComponent

button_component.rb

button_component.html.erb

button_component.css

Example

<%= render(ButtonComponent.new(text:"Save")) %>

Benefits

βœ… Reusable

βœ… Testable

βœ… Maintainable


🎭 Decorators / Presenters

Avoid formatting inside models.

Example

UserPresenter.new(user).full_name

Instead of

user.first_name + user.last_name

⚑ Hotwire

Hotwire allows modern SPA-like experience without React.

Components

Turbo

Stimulus

Advantages

βœ… Less JavaScript

βœ… Faster

βœ… SEO Friendly

βœ… Rails Native


πŸš€ Turbo

Instead of

Reload Entire Page

Turbo only replaces changed content.

Before

Entire page reload

↓

After

Only one frame updates

Turbo Streams

Real-time notifications

Comments

Chat

Likes

Dashboard

βš™ Stimulus JS

Small JavaScript controllers.

Example

export default class extends Controller{

connect(){

console.log("Connected")

}

}

Perfect for

Dropdown

Modal

Clipboard

Tabs

Accordion

Filters

🎨 CSS Strategy

Recommended

TailwindCSS ⭐⭐⭐⭐⭐

Bootstrap ⭐⭐⭐⭐

Bulma ⭐⭐⭐

Foundation ⭐⭐

My recommendation:

Rails + Tailwind + ViewComponent

Excellent combination.


πŸ“¦ Asset Management

Rails 8 options

βœ… Import Maps

βœ… jsbundling

βœ… cssbundling

βœ… esbuild

βœ… Bun

Choose based on project complexity.


⚑ UI Optimization

Lazy Images

<img loading="lazy">

Image Compression

Use

WebP

AVIF

Minify CSS

Remove unused CSS.


Tree Shaking

Remove unused JavaScript.


Split Bundles

Don’t load

Admin JS

Dashboard JS

Checkout JS

Together.


πŸš€ View Caching

Russian Doll Caching

<% cache @product do %>

...

<% end %>

Huge speed improvement.


πŸ“ˆ Pagination

Instead of loading

50,000 records

Use

Pagy ⭐⭐⭐⭐⭐

Kaminari ⭐⭐⭐⭐

πŸ“± Responsive Design

Always design

Mobile First

Breakpoints

Mobile

Tablet

Desktop

β™Ώ Accessibility

Always include

Alt Tags

ARIA Labels

Keyboard Navigation

Focus States

Proper Colors

Accessibility improves SEO too.


βš› React + Rails

There are several ways to combine React with Rails.


Option 1

Rails + React Components

Rails

↓

ERB

↓

React Widget

Good for

Dashboard

Charts

Comments

Filters

Option 2

Rails API + React SPA ⭐⭐⭐⭐⭐

Rails API

↓

JSON

↓

React

↓

Browser

Perfect for

Large SaaS

CRM

ERP

Enterprise Apps

Option 3

Rails + Next.js ⭐⭐⭐⭐⭐

Rails API

↓

Next.js

↓

SSR

↓

Browser

Benefits

βœ… SEO

βœ… Speed

βœ… React ecosystem

βœ… Excellent UX


🟒 Vue + Rails

Excellent developer experience.

Smaller than React.

Perfect for

Admin Panels

Dashboards

CMS

πŸ”΄ Angular + Rails

Best for

Large Enterprise

Government

Banking

ERP

Heavy but powerful.


⚑ Inertia.js

Very interesting architecture.

Rails

↓

Inertia

↓

Vue / React

No REST API required.

Feels like SPA.


🧠 Choosing the Right Frontend

Project Recommendation
Blog Rails Views + Turbo
CMS Rails + Hotwire
Startup MVP Rails + Hotwire + Stimulus
SaaS Rails API + React
Enterprise Rails API + Next.js
Real-time App Rails + Hotwire + ActionCable
Ecommerce Rails + React
Marketplace Rails API + Next.js
CRM React + Rails API
ERP Angular + Rails API

πŸ“‚ Ideal Enterprise Folder Structure

app/

components/

helpers/

views/

layouts/

shared/

javascript/

controllers/

stimulus/

stylesheets/

tailwind/

assets/

⚑ Performance Checklist

βœ… Use partials

βœ… Use ViewComponent

βœ… Cache views

βœ… Compress images

βœ… Lazy load images

βœ… Turbo Frames

βœ… Turbo Streams

βœ… Stimulus

βœ… Paginate

βœ… Minify CSS

βœ… Remove unused JS

βœ… Bundle splitting

βœ… Responsive design

βœ… Accessibility

βœ… Lighthouse optimization


❌ Common Mistakes

🚫 Business logic in views

🚫 Giant ERB files

🚫 Duplicate HTML

🚫 No caching

🚫 Huge JavaScript bundles

🚫 No responsive design

🚫 Too many database queries in templates

🚫 Ignoring accessibility

🚫 Overusing React for simple interactions

🚫 Not optimizing images


πŸ† My Recommended Stack (2026)

For most new Rails projects, a balanced stack looks like this:

Backend

  • Ruby on Rails
  • PostgreSQL
  • Redis

UI

  • Tailwind CSS
  • ViewComponent
  • Hotwire (Turbo + Stimulus)

JavaScript

  • Bun or esbuild
  • TypeScript (for medium/large projects)

Performance

  • Fragment caching
  • CDN for assets
  • WebP/AVIF images
  • Pagy
  • Import only the JavaScript you need

For applications requiring highly interactive dashboards, offline support, or complex client-side state management, expose a Rails JSON API and build the frontend with React or Next.js. This provides the flexibility of the React ecosystem while keeping Rails focused on business logic and APIs.


🎯 Final Thoughts

A beautiful Rails application isn’t created by writing more HTMLβ€”it’s built by structuring your UI for maintainability, performance, and scalability.

Follow these guiding principles:

  • 🎨 Keep views simple and presentation-focused.
  • 🧩 Build reusable UI with components.
  • ⚑ Use Hotwire for fast interactions without unnecessary JavaScript.
  • πŸš€ Reach for React, Vue, or Next.js when your application truly benefits from SPA capabilities.
  • πŸ“ˆ Optimize continuously with caching, lazy loading, responsive design, and accessibility.

Remember:

β€œThe best UI is not the one with the most animationsβ€”it’s the one that helps users achieve their goals quickly, intuitively, and reliably.”

Happy Coding! πŸš€β€οΈ

© Lakhveer Singh Rajput - Blogs. All Rights Reserved.