rails-turbolisted
Install: claude install-skill mickzijdel/rails-toolkit
# Rails Turbo Patterns
## Pattern 1: Turbo Stream Flash Messages
The standard flash doesn't render in Turbo Stream responses (no full page render). A `TurboFlash` concern provides a helper that replaces the flash area as a stream action:
```ruby
# app/controllers/concerns/turbo_flash.rb
module TurboFlash
extend ActiveSupport::Concern
included do
helper_method :turbo_stream_flash
end
private
def turbo_stream_flash(**flash_options)
turbo_stream.replace(:flash, partial: "layouts/shared/flash", locals: { flash: flash_options })
end
end
```
```erb
<%# app/views/layouts/shared/_flash.html.erb %>
<%= turbo_frame_tag :flash do %>
<% if notice = flash[:notice] || flash[:alert] %>
<div class="flash" data-controller="element-removal" data-action="animationend->element-removal#remove">
<div class="flash__inner shadow"><%= notice %></div>
</div>
<% end %>
<% end %>
```
```erb
<%# usage in a turbo_stream.erb template %>
<%= turbo_stream_flash(notice: "Card saved successfully") %>
<%= turbo_stream.replace(@card) %>
```
---
## Pattern 2: Multiple Format Responses
Turbo sends requests with the `text/vnd.turbo-stream.html` Accept header, so `format.turbo_stream` in a `respond_to` block picks up the matching `.turbo_stream.erb` template automatically. The full multi-format pattern (HTML/JSON/Turbo Stream conventions) lives in [[rails-controllers]] Pattern 7.
---
## Pattern 3: Broadcasting from Models
`broadcasts_refreshes` in a model conc