Skip to content

Instantly share code, notes, and snippets.

@usutani
Last active October 26, 2021 13:03
Show Gist options
  • Save usutani/e8e233bda58c3c954057bf4217edd3ad to your computer and use it in GitHub Desktop.
Save usutani/e8e233bda58c3c954057bf4217edd3ad to your computer and use it in GitHub Desktop.
shared.erb --- turbo_stream create error_explanation
mkdir app/views/shared
touch app/views/shared/_turbo_stream_error_explanation.erb
<% if model.errors.any? %>
<%= turbo_stream.update :error_explanation do %>
<h2><%= pluralize(model.errors.count, 'error') %> prohibited this <%= model.model_name.name %> from being saved:</h2>
<ul>
<% model.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
<% end %>
<% else %>
<%= turbo_stream.update :error_explanation, '' %>
<% end %>
<%= render 'shared/turbo_stream_error_explanation', model: @message %>
<div id="error_explanation"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment