erb

ruby
class CommentsController < ApplicationController
  before_action :set_post

  def create
    @comment = @post.comments.build(comment_params)

Turbo Streams fallback to HTML for older clients

rails hotwire turbo-streams
by codesnips 4 tabs
ruby
class WizardsController < ApplicationController
  before_action :load_draft

  def step_1
    render_step(1)
  end

Hotwire-powered multi-step forms

hotwire turbo forms
by Jordan Lee 3 tabs
erb
<article class="post">
  <h1><%= @post.title %></h1>
  <%= simple_format @post.body %>

  <!-- Lazy load comments when scrolled into view -->
  <%= turbo_frame_tag "post_#{@post.id}_comments",

Lazy-loading Turbo Frames for performance

hotwire turbo performance
by Jordan Lee 3 tabs
css
.confirm-dialog {
  border: none;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 26rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);

Stimulus: resilient confirmation for destructive actions

rails stimulus hotwire
by codesnips 3 tabs
erb
<div class="layout" data-controller="viewport">
  <%= turbo_frame_tag "master", class: "master-pane" do %>
    <h1>Products</h1>
    <ul class="product-list">
      <% @products.each do |product| %>
        <li>

Turbo Frames: conditional frame navigation for mobile vs desktop

rails hotwire responsive
by codesnips 4 tabs
erb
<%= turbo_frame_tag dom_id(flag) do %>
  <tr class="flag-row">
    <td class="flag-name"><%= flag.name %></td>
    <td class="flag-env"><%= flag.environment %></td>
    <td class="flag-state">
      <span class="badge badge--<%= flag.enabled? ? 'on' : 'off' %>">

Admin “quick toggle” with Turbo Streams and a single partial

rails hotwire turbo
by codesnips 4 tabs
ruby
class ReportsController < ApplicationController
  def create
    @report = current_user.reports.create!(
      title: report_params[:title],
      status: :pending,
      progress: 0

Turbo Streams: broadcast from a job for long operations

rails turbo hotwire
by codesnips 3 tabs
ruby
class ApplicationController < ActionController::Base
  before_action :authenticate_user!

  rescue_from ActionController::InvalidAuthenticityToken do
    handle_unauthenticated(reason: :csrf)
  end

Turbo Streams: partial page auth failure handling

rails turbo hotwire
by codesnips 3 tabs
ruby
# Controller responding with Turbo Stream
class PostsController < ApplicationController
  def create
    @post = Post.new(post_params)

    if @post.save

Hotwire Turbo for SPA-like user experiences

ruby rails hotwire
by Sarah Mitchell 3 tabs
javascript
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["parent", "child"]
  static values = {
    options: Object,

Stimulus controller for dependent select dropdowns

stimulus javascript forms
by Jordan Lee 2 tabs
javascript
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["dialog", "message"]

  connect() {

Custom confirm dialog with Stimulus (better than window.confirm)

rails hotwire stimulus
by codesnips 3 tabs
erb
<%= turbo_frame_tag 'modal' %>

Keyboard shortcut “command palette” modal (Hotwire-first)

rails hotwire stimulus
by Henry Kim 3 tabs