forked from fixin.me/fixin.me
Render flash messages for html and turbo_stream
This commit is contained in:
parent
a4f113ad48
commit
8d63ed62ea
@ -198,9 +198,6 @@ input[type=text]:read-only {
|
||||
}
|
||||
|
||||
|
||||
.flashes {
|
||||
height: 2.1rem;
|
||||
}
|
||||
.flash {
|
||||
align-items: center;
|
||||
border-radius: 0.2rem;
|
||||
|
@ -1,4 +1,5 @@
|
||||
module ApplicationHelper
|
||||
# TODO: replace legacy content_tag with tag.tagname
|
||||
class TabularFormBuilder < ActionView::Helpers::FormBuilder
|
||||
(field_helpers - [:label]).each do |selector|
|
||||
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
||||
@ -88,6 +89,15 @@ module ApplicationHelper
|
||||
image_element_to(:link, name, image, options, html_options)
|
||||
end
|
||||
|
||||
def render_flash_messages
|
||||
flash.map do |entry, message|
|
||||
tag.div class: "flash #{entry}" do
|
||||
tag.div(sanitize(message)) + tag.button(sanitize("×"), tabindex: -1,
|
||||
onclick: "this.parentElement.style.display='none';")
|
||||
end
|
||||
end.join.html_safe
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def image_element_to(type, name, image = nil, options = nil, html_options = {})
|
||||
|
@ -36,16 +36,9 @@
|
||||
<% end %>
|
||||
</header>
|
||||
|
||||
<!--
|
||||
<div class="flashes">
|
||||
<% flash.each do |entry, message| %>
|
||||
<div class="flash <%= entry %>">
|
||||
<div><%= sanitize message %></div>
|
||||
<button tabindex="-1" onclick="this.parentElement.style.display='none';">×</button>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
-->
|
||||
<div id="flashes">
|
||||
<%= render_flash_messages %>
|
||||
</div>
|
||||
|
||||
<%# Allow overwriting/clearing navigation menu for some views %>
|
||||
<nav class="navigation">
|
||||
|
4
app/views/layouts/application.turbo_stream.erb
Normal file
4
app/views/layouts/application.turbo_stream.erb
Normal file
@ -0,0 +1,4 @@
|
||||
<%= turbo_stream.update :flashes do %>
|
||||
<%= render_flash_messages %>
|
||||
<% end %>
|
||||
<%= yield %>
|
Loading…
x
Reference in New Issue
Block a user