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.
Letβs build Rails applications like professionals! π
π Table of Contents
- Understanding Rails Views
- MVC & View Responsibility
- Principles of Clean UI Development
- Rails View Folder Structure
- ERB Best Practices
- Layouts & Partials
- Helpers
- View Components
- Presenters & Decorators
- Hotwire
- Turbo
- Stimulus JS
- Asset Management
- CSS Architecture
- UI Optimization Techniques
- Caching Views
- Lazy Loading
- Responsive Design
- Accessibility
- React + Rails
- Vue + Rails
- Angular + Rails
- Next.js + Rails API
- Inertia.js
- Hybrid Architecture
- Complete UI Folder Structure
- Performance Checklist
- Common Mistakes
- 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.