Modern Rails apps can feel incredibly responsive without adopting a full JavaScript framework. One of the simplest ways to achieve that is with Turbo Frames, which let you update only part of a page after a request.
Imagine a list of articles where clicking "Edit" replaces just the article card with an edit form instead of reloading the entire page.
In your view:
<%= turbo_frame_tag @article do %>
<h2><%= @article.title %></h2>
<p><%= @article.body %></p>
<%= link_to "Edit", edit_article_path(@article) %>
<% end %>
Then, in edit.html.erb:
<%= turbo_frame_tag @article do %>
<%= render "form", article: @article %>
<% end %>
And in the controller:
def update
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to @article
else
render :edit, status: :unprocessable_entity
end
end
Because both views use the same turbo_frame_tag, Turbo automatically swaps only that frame's content. Users experience a smoother interface with less bandwidth and fewer full-page refreshes.
Turbo Frames work especially well for:
- Editing records inline
- Loading sidebar content
- Pagination within a section
- Dashboard widgets
If you're building a Rails application and want a more dynamic user experience without the complexity of a single-page application, Turbo Frames are an excellent feature to explore. They embrace Rails conventions while keeping your application fast, maintainable, and enjoyable to build.