Skip to content

Instantly share code, notes, and snippets.

@heratyian
Last active October 24, 2024 15:04
Show Gist options
  • Save heratyian/1c556c443fd9c76461fa4b931acf70c3 to your computer and use it in GitHub Desktop.
Save heratyian/1c556c443fd9c76461fa4b931acf70c3 to your computer and use it in GitHub Desktop.
flashes

Demo of how to add bootstrap alerts for dismissable flashes

docs

app/views/shared/_flashes.html.erb


<% if notice.present? %>
  <div class="alert alert-success alert-dismissible fade show" role="alert">
    <%= notice %>
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  </div>
<% end %>

<% if alert.present? %>
  <div class="alert alert-warning alert-dismissible fade show" role="alert">
    <%= alert %>
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
  </div>
<% end %>

app/views/layouts/application.html.erb

<body>
  <%= render "shared/flashes" %>
  <%= yield %>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment