Render flash messages for html and turbo_stream

This commit is contained in:
cryptogopher 2024-01-14 03:19:20 +01:00
parent a4f113ad48
commit 8d63ed62ea
4 changed files with 17 additions and 13 deletions

View File

@ -198,9 +198,6 @@ input[type=text]:read-only {
} }
.flashes {
height: 2.1rem;
}
.flash { .flash {
align-items: center; align-items: center;
border-radius: 0.2rem; border-radius: 0.2rem;

View File

@ -1,4 +1,5 @@
module ApplicationHelper module ApplicationHelper
# TODO: replace legacy content_tag with tag.tagname
class TabularFormBuilder < ActionView::Helpers::FormBuilder class TabularFormBuilder < ActionView::Helpers::FormBuilder
(field_helpers - [:label]).each do |selector| (field_helpers - [:label]).each do |selector|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
@ -88,6 +89,15 @@ module ApplicationHelper
image_element_to(:link, name, image, options, html_options) image_element_to(:link, name, image, options, html_options)
end end
def render_flash_messages
flash.map do |entry, message|
tag.div class: "flash #{entry}" do
tag.div(sanitize(message)) + tag.button(sanitize("&times;"), tabindex: -1,
onclick: "this.parentElement.style.display='none';")
end
end.join.html_safe
end
private private
def image_element_to(type, name, image = nil, options = nil, html_options = {}) def image_element_to(type, name, image = nil, options = nil, html_options = {})

View File

@ -36,16 +36,9 @@
<% end %> <% end %>
</header> </header>
<!-- <div id="flashes">
<div class="flashes"> <%= render_flash_messages %>
<% flash.each do |entry, message| %> </div>
<div class="flash <%= entry %>">
<div><%= sanitize message %></div>
<button tabindex="-1" onclick="this.parentElement.style.display='none';">&times;</button>
</div>
<% end %>
</div>
-->
<%# Allow overwriting/clearing navigation menu for some views %> <%# Allow overwriting/clearing navigation menu for some views %>
<nav class="navigation"> <nav class="navigation">

View File

@ -0,0 +1,4 @@
<%= turbo_stream.update :flashes do %>
<%= render_flash_messages %>
<% end %>
<%= yield %>