Go back to the main page

Better looking Rails errors with Bootstrap and Fontawesome

This article is over 2 years old. Proceed with caution.

Regards ♨ – Minimul

 

Not to shabby, eh?

<!-- Standard form_for with render a partial, which is the next snippet -->
<%= form_for(@template) do |f| %>
<%= render 'shared/error_message', model: @template %>
<div class="field">


<!-- app/views/shared/_error_message.html.erb -->
<% if model.errors.any? %>
<div id="error_explanation">
  <h2><i class="fa fa-flag fa-2x pull-left"></i> <%= pluralize(model.errors.count, "error") %> prohibited this template from being saved:</h2>
  <ul class="fa-ul">
  <% model.errors.full_messages.each do |message| %>
    <li><i class="fa-li fa fa-star"></i> <%= message %></li>
  <% end %>
  </ul>
</div>
<% end %>


<!-- Styling -->
#error_explanation {
  @extend .alert;
  @extend .alert-danger;
  width: 50%;
  h2 {
    margin-top: 10px;
    font-size: 16px;
  }
  ul {
    margin-top: 2em;
  }
}
Comment on this micro post?