Skip to content

Instantly share code, notes, and snippets.

@heratyian
Created November 13, 2023 16:39
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

<div class="row">
  <div class="col-md-12">
    <% 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 %>
  </div>
</div>

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