mkdir app/views/shared
touch app/views/shared/_turbo_stream_error_explanation.erb
Last active
October 26, 2021 13:03
-
-
Save usutani/e8e233bda58c3c954057bf4217edd3ad to your computer and use it in GitHub Desktop.
shared.erb --- turbo_stream create error_explanation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= render 'shared/turbo_stream_error_explanation', model: @message %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="error_explanation"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment