Views, Layouts, Partials, Helpers, Forms, and Hotwire/Turbo Frontend Basics
Build user-facing pages with ERB templates, reusable partials, Rails form helpers, and modern Hotwire-style interactions.
Inside this chapter
- ERB Templates and Layouts
- Partials and Helpers
- Forms in Rails
- Hotwire and Modern Rails UX
Series navigation
Study the chapters in order for the clearest path from Rails beginner concepts to advanced production architecture. Use the previous and next links at the bottom of each page to move through the full tutorial series.
ERB Templates and Layouts
Rails commonly uses ERB templates to combine HTML with embedded Ruby. Layouts wrap shared page structure such as headers, footers, navigation, and flash messages. This keeps rendering organized and reduces duplication across pages.
<h1><%= @book.title %></h1>
<p>Price: <%= number_to_currency(@book.price) %></p> Partials and Helpers
Partials let teams extract reusable template fragments such as cards, form sections, table rows, or navigation blocks. Helpers encapsulate presentation-related logic. Strong developers avoid putting complex business rules directly into view files.
Forms in Rails
<%= form_with model: @book do |form| %>
<%= form.label :title %>
<%= form.text_field :title %>
<%= form.label :price %>
<%= form.number_field :price %>
<%= form.submit %>
<% end %>
Rails form helpers understand model names, field errors, parameter nesting, and CSRF protection, which is why they are more powerful than manually assembled form markup alone.
Hotwire and Modern Rails UX
Modern Rails often uses Turbo and Stimulus as part of the Hotwire approach. This allows teams to deliver fast, interactive experiences without turning every feature into a large client-side SPA. Turbo handles page transitions and partial updates well, while Stimulus provides lightweight JavaScript behavior where needed.